On Fri, 20 Jun 2003 10:52:26 +0900, Yukihiro Matsumoto wrote:
> In message "Re: collect info about ruby-api"
>     on 03/06/20, "Simon Strandgaard" <0bz63fz3m1qt3001 / sneakemail.com> writes:
> 
> |1)   rb_funcall3()  what is purpose with it ?
> |     is there any _understandable_ examples around ?
> 
> It's almost like rb_funcall2() but raises error when it tries to call
> private method.

So rb_funcall3 is equal to a ruby-method call, like this:

> cat test.rb
class Test
private
        def test
                puts "ok"
        end
end
Test.new.test   # is rb_funcall3 going on ?
> ruby test.rb
test.rb:7: private method `test' called for #<Test:0x8106cc8> (NoMethodError)
>


Furthermore rb_funcall + rb_funcall2 can access *any* function, even
private ones! 

> cat main.c
#include <ruby.h>
int main(int argc, char *argv[]) {
        VALUE data;
        ruby_init();
        data = rb_eval_string("class Test\nprivate\ndef test\nputs \"ok\"\nend\nend\nTest.new");
        rb_funcall(data, rb_intern("test"), 0);         /* outputs 'ok' */
        /*rb_funcall2(data, rb_intern("test"), 0, 0);*/ /* outputs 'ok' */
        /*rb_funcall3(data, rb_intern("test"), 0, 0);*/ /* fails as its suppose to */
        ruby_finalize();
        return 0;
}
> ./a.out
ok
>

People can access private-methods by an accident.. I think that rb_funcall
and rb_funcall2 is behaving in God mode (disrespecting privacy :-)
Shouldn't rb_funcall3 be advertised a lot more ??? 


 
> |2)   rb_eval_string_wrap()  how is it different from
> |     rb_eval_string_protect()... scoping ?
> |     is there any examples which demonstrates this
> |     difference ? 
> 
> It evaluates string under anonymous module, just like "load(path, true).

Sorry, I don't understand..  

  rb_eval_string_wrap(), evaluates under anonymous module.

  rb_eval_string_protect(), evaluates under ??current context??.

I don't think I understand the consequences putting it under a anonymous
module.. can someone enligthen me ?
Examples would be really nice :-)

--
Simon Strandgaard