[MacRuby-devel] integrating macruby into cocoa apps

Benjamin Stiglitz ben at tanjero.com
Tue Mar 18 15:16:59 PDT 2008

>> However, I don't see any obvious
>> way to hand off an NSString with code and have it execute in some
>> environment.  Does such an API exist?
> At the moment the only thing you can do is to use the C APIs, which
> are not really user-friendly.
> We could introduce a convenience facility to evaluate code.
>   NSNumber *number = [@"1+2+3+4+5" evaluateAsRubyExpression];

This is OK, but I’m not too keen on adding the extension method when  
there’s already something else that works.

> Or directly calling Kernel#eval from Objective-C, as Ben said, which
> should work in theory, though I didn't try it yet.

This will be easier when strings bridge properly. It seems like the  
cleanest way to me. You can even make a new proc and then call it over  
and over again.

RbObject *squareIt = [RbKernel eval:@"Proc.new {|n| n*n}"];
NSNumber *twentyFive = [squareIt call:[NSNumber numberWithInt:5]];

All this being said, it’d be nice to have a real quick way to boot up  
an embedded MR for “normal” Objective-C apps.


More information about the MacRuby-devel mailing list