[MacRuby-devel] MacRuby class inside obj-c
Laurent Sansonetti
lsansonetti at apple.com
Tue May 18 14:44:46 PDT 2010
Hi Louis-Philippe,
Assuming MacRuby code defines:
class Foo
def initialize(message)
@message
end
def hello
puts "hello #{message}"
end
end
You should be able to retrieve a reference to Foo using:
Class Foo = [[MacRuby sharedRuntime] evaluateString:@"Foo"];
Or, more simply:
Class foo = NSClassFromString(@"Foo");
You might want to use the first way in case the class has a complex path (if it's defined inside modules, like "Foo::Bar").
Later, you can send messages to it.
id obj = [Foo performRubySelector:@selector(new:) withArguments: @"objc", nil];
[obj performRubySelector:@selector(hello)];
Laurent
On May 18, 2010, at 2:31 PM, Louis-Philippe wrote:
> Hi,
> I don't know if this is the good list to ask this question as it is my first...
> So,
>
> I saw how I can have a MacRuby cocoa app, importing objective-c classes.
> I can't find info on how to do the opposite... having an Objective-C cocoa app, importing and using MacRuby Classes...
>
> All I managed to do is to "evaluateFileAtPath:" and "evaluateString:"
>
> Thanks!
>
> L-P
> _______________________________________________
> 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