passing self to a c module function

J

John

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
 
G

George Ogata

John said:
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. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top