Forum: Ruby passing self to a c module function

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
John (Guest)
on 2006-03-10 00:49
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
George O. (Guest)
on 2006-03-10 02:31
(Received via mailing list)
John <removed_email_address@domain.invalid> 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.  :-)
This topic is locked and can not be replied to.