# Passing self to a c module function

**URL:** <https://www.ruby-forum.com/t/passing-self-to-a-c-module-function/54612>\
**Category:** Ruby\
**Created:** [March 9, 2006, 11:49pm UTC](https://www.ruby-forum.com/t/passing-self-to-a-c-module-function/54612 "2006-03-09T23:49:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 9, 2006, 11:49pm UTC](https://www.ruby-forum.com/t/passing-self-to-a-c-module-function/54612/1 "2006-03-09T23:49:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 10, 2006, 1:31am UTC](https://www.ruby-forum.com/t/passing-self-to-a-c-module-function/54612/2 "2006-03-10T01:31:04Z")

</div>

John [removed\_email\_address@domain.invalid](mailto: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. 🙂
