[MacRuby-devel] MacRuby classes delete/overwrite Objective-C classes?
Caio Chassot
lists at caiochassot.com
Fri Feb 11 22:40:21 PST 2011
On 2011-02-12, at 01:59 , Robert Payne wrote:
>
> The behavior I'm expecting is to see "Hello world" in the console but it seems as if the entire Objective-C method was deleted. I don't have a method in the Ruby class called helloWorld.
There's likely something wrong somewhere else in your project. If you post the whole compilable thing to github maybe we can take a look.
This works:
$ cat foo.m
#import <MacRuby/MacRuby.h>
@interface Foo : NSObject {}
-(NSString*) helloWorld;
@end
@implementation Foo
-(NSString*) helloWorld {
return @"hello";
}
@end
int main (int argc, const char * argv[]) {
[[MacRuby sharedRuntime] evaluateFileAtPath:@"foo.rb"];
Foo* foo = [Foo new];
NSLog(@"IM IN UR OBJC %@", [foo helloWorld]);
NSLog(@"IM IN UR OBJC %@", [foo performRubySelector:@selector(helloRuby)]);
// you could use the following too but it would generate a compile warning:
// NSLog(@"IM IN UR OBJC %@", [foo helloRuby]);
return 0;
}
$ cat foo.rb
class Foo
def helloRuby
"hello ruby"
end
end
NSLog("IM IN UR RUBY: %@", Foo.new.helloWorld)
NSLog("IM IN UR RUBY: %@", Foo.new.helloRuby)
$ clang -o foo foo.m -fobjc-gc-only -framework MacRuby -framework Foundation
$ ./foo
2011-02-12 04:36:21.709 foo[26994:903] IM IN UR RUBY: hello
2011-02-12 04:36:21.713 foo[26994:903] IM IN UR RUBY: hello ruby
2011-02-12 04:36:21.714 foo[26994:903] IM IN UR OBJC hello
2011-02-12 04:36:21.714 foo[26994:903] IM IN UR OBJC hello ruby
More information about the MacRuby-devel
mailing list