[MacRuby-devel] Creating ruby objects in Objective-C

Alan Skipp al_skipp at fastmail.fm
Tue Jan 18 03:39:59 PST 2011


Thanks Laurent,
I'd forgotten about performRubySelector:. The ruby class I'm using takes 2 args, one of them a default argument, so I created an initWith method to work around that - problem solved now. 

Alan

On 17 Jan 2011, at 21:51, Laurent Sansonetti wrote:

> Hi Alan,
> 
> When performing Ruby selectors on Ruby objects from Objective-C, the performRubySelector: method should be used instead of performSelector:, because it takes care of special Ruby semantics such as splat or default arguments.
> 
> 	[RubyClass performRubySelector:@selector(new:) withArguments: arg, NULL];
> 
> Laurent
> 
> On Jan 17, 2011, at 5:05 AM, Alan Skipp wrote:
> 
>> Hi,
>> Is there any way to inform an Objective-C class of the existence of a ruby class so that instances can be created in Objective-C code?
>> Currently I am doing the following:
>> 
>> [[MacRuby sharedRuntime] evaluateString:[NSString stringWithFormat:@"RubyClass.new('%@')", arg]];
>> 
>> If I'm adding quite a few objects (300+) to an array in a loop, this line of code is quite slow. My assumption (which may be false) is that either of the 3 options below would be quicker.
>> 
>> [RubyClass performSelector:@selector(new:) withObject:arg];
>> [RubyClass new:arg];    
>> [[RubyClass alloc] initWithArg:arg];   
>> 
>> Are any of those options (or an equivalent) a possibility?
>> 
>> Alan
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> 
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20110118/b2787aee/attachment.html>


More information about the MacRuby-devel mailing list