[MacRuby-devel] MacRuby class inside obj-c

Louis-Philippe default at spiralix.org
Tue May 18 15:05:30 PDT 2010


great!
I can even seem to send messages directly to my MacRuby classes and
instances...
like:
id obj = [Foo new:@"objc"];
and
[obj hello];

but in the second case I get a compiler warning: "No -hello method found"??

2010/5/18 Laurent Sansonetti <lsansonetti at apple.com>

> 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
>
> _______________________________________________
> 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/20100518/ae3235bf/attachment.html>


More information about the MacRuby-devel mailing list