[MacRuby-devel] MacRuby 0.5b1: Reloading classes at runtime

Frank Illenberger illenberger at mac.com
Thu Nov 12 16:03:19 PST 2009


Thanks for your quick answer. But sadly, it does not seem to work.

My application is a regular Objective-C application and uses MacRuby to load plug-in ruby classes which reside in their own .rb file.
First I implemented the loading like this:

NSString* path = @"/path/to/MyPlugInClass.rb";
[[MacRuby sharedRuntime] evaluateFileAtPath: path]
id plugInInstance = [[NSClassFromString(@"MyPlugInClass") alloc] init];

This is working fine when the class is loaded for the first time. Reloading the class while the app keeps running after the .rb has been edited however does not refresh the class.

Then I tried to use the "load" command as you suggested:

NSString* path = @"/path/to/MyPlugInClass.rb";
NSString* command = [NSString stringWithFormat:@"load '%@'", path];
[[MacRuby sharedRuntime] evaluateString: command]
id plugInInstance = [[NSClassFromString(@"MyPlugInClass") alloc] init];

But it shows the same behavior as the first case. 
Am I doing something wrong here?

Cheers

Frank

Am 12.11.2009 um 20:40 schrieb Matt Aimonetti:

> This is the right place to ask this kind of questions and welcome to the list :)
> 
> What kind of file are you loading? If you are reloading a ruby, you might want to try to use load instead of require.
> http://www.fromjavatoruby.com/2008/10/require-vs-load.html
> 
> - Matt
> 
> 
> On Thu, Nov 12, 2009 at 11:11 AM, Frank Illenberger <illenberger at mac.com> wrote:
> Hello folks,
> 
> please excuse me if this is not the right mailing list to post this question:
> 
> I am currently porting an application from PyObjC to MacRuby. Under PyObjC it is possible to reload a .py file containing a class definition at runtime. -[MacRuby evaluateFileAtPath:]  works fine for me loading a class for the first time. But after is loaded, it is not updated when called again. Does anybody know if there is a way to make this work with MacRuby?
> 
> Thanks and cheers
> 
> Frank

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


More information about the MacRuby-devel mailing list