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

Eloy Durán eloy.de.enige at gmail.com
Mon Jan 17 05:32:43 PST 2011


After the Ruby code that defines the class has been evaled, you should be able to do the following:

Class rubyClass = NSClassFromString(@"RubyClass");
id rubyObject = [[rubyClass alloc] init];

On Jan 17, 2011, at 2:05 PM, 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



More information about the MacRuby-devel mailing list