# Global rb\_funcall

**URL:** <https://www.ruby-forum.com/t/global-rb-funcall/51129>\
**Category:** Ruby\
**Created:** [December 26, 2005, 11:30pm UTC](https://www.ruby-forum.com/t/global-rb-funcall/51129 "2005-12-26T23:30:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SSSISO-8859-1SQSSim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8e7dd6/32.png) [@SSSISO-8859-1SQSSim](https://www.ruby-forum.com/u/SSSISO-8859-1SQSSim)\
**Post date:** [December 26, 2005, 11:30pm UTC](https://www.ruby-forum.com/t/global-rb-funcall/51129/1 "2005-12-26T23:30:02Z")

</div>

Hi,

i’m embedding ruby into a C++, how do i call _global_ functions from C?

like

rb\_funcall2(??, rb\_intern(“test”), 0, NULL);

thanks

Simon

---

<div class="post-metadata">

**Author:** ![SSSISO-8859-1SQSSim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8e7dd6/32.png) [@SSSISO-8859-1SQSSim](https://www.ruby-forum.com/u/SSSISO-8859-1SQSSim)\
**Post date:** [December 26, 2005, 11:55pm UTC](https://www.ruby-forum.com/t/global-rb-funcall/51129/2 "2005-12-26T23:55:18Z")

</div>

=?ISO-8859-1?Q?Simon\_Kr=F6ger?= wrote:

> Hi,
> 
> i’m embedding ruby into a C++, how do i call _global_ functions from C?
> 
> like
> 
> rb\_funcall2(??, rb\_intern(“test”), 0, NULL);
> 
> thanks

All of the global methods become singleton methods of  
the top-level Object object, so you should be able to  
refer to rb\_cObject (I am unable to test). If that  
does not work, see if README.EXT provides any clues.

> Simon

E

---

<div class="post-metadata">

**Author:** ![SSSISO-8859-1SQSSim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8e7dd6/32.png) [@SSSISO-8859-1SQSSim](https://www.ruby-forum.com/u/SSSISO-8859-1SQSSim)\
**Post date:** [December 27, 2005, 12:36am UTC](https://www.ruby-forum.com/t/global-rb-funcall/51129/3 "2005-12-27T00:36:17Z")

</div>

Eero S. wrote:

> > thanks
> 
> E

I was thinking of that possibility and dismissed the thought because  
“thats the class, not the object…”. Well, from time to time my past  
trips me up.

Thanks !

Simon

---

<div class="post-metadata">

**Author:** ![SSSISO-8859-1SQSSim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8e7dd6/32.png) [@SSSISO-8859-1SQSSim](https://www.ruby-forum.com/u/SSSISO-8859-1SQSSim)\
**Post date:** [December 27, 2005, 4:52am UTC](https://www.ruby-forum.com/t/global-rb-funcall/51129/4 "2005-12-27T04:52:00Z")

</div>

Hi,

At Tue, 27 Dec 2005 07:55:32 +0900,  
Eero S. wrote in [ruby-talk:172589]:

> refer to rb\_cObject (I am unable to test). If that  
> does not work, see if README.EXT provides any clues.

They are private instance methods of Object.

$ ruby -e ‘def foo;end; p Object.private\_instance\_methods.grep(/foo/)’  
[“foo”]

So the receiver is not a matter,

rb\_funcall2(Qnil, rb\_intern(“test”), 0, NULL);  
rb\_funcall2(INT2FIX(999), rb\_intern(“test”), 0, NULL);  
rb\_funcall2(rb\_cArray, rb\_intern(“test”), 0, NULL);  
rb\_funcall2(rb\_str\_new(0, 0), rb\_intern(“test”), 0, NULL);  
rb\_funcall2(rb\_ary\_new(), rb\_intern(“test”), 0, NULL);  
rb\_funcall2(rb\_hash\_new(), rb\_intern(“test”), 0, NULL);  
rb\_funcall2(rb\_module\_new(), rb\_intern(“test”), 0, NULL);

all work.
