[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

passing self to a c module function

John K

3/9/2006 10:50:00 PM

When I write a module function in a C extension, I found that I need to
include "VALUE self" as the first argument, just as I do when I write a
class method in a C extension. Why is this?
Thanks,
John

--
Posted via http://www.ruby-....


1 Answer

George Ogata

3/9/2006 11:47:00 PM

0

John <progml@ishkabeebee.com> writes:

> When I write a module function in a C extension, I found that I need to
> include "VALUE self" as the first argument, just as I do when I write a
> class method in a C extension. Why is this?

You might want it so you can call other module functions on the same
object.

rb_funcall2(self, rb_intern("boo!"), 0, NULL)

Note that there's *always* a self in ruby. Everywhere. And since
there's no global `self' handle, it makes sense to pass it in to all
the C method implementations. Nice and consistent, at least. :-)