[MacRuby-devel] Calling ObjC method

Laurent Sansonetti lsansonetti at apple.com
Tue Mar 4 19:51:01 PST 2008


Hi Satoshi-san,

It's most probably a duplicate of

http://trac.macosforge.org/projects/ruby/ticket/14

The problem is that when you call #test on your object, MacRuby tries  
to call Kernel#test (because Kernel is included in NSObject). And this  
fails.

You can reproduce it by calling #test on any object:

$ /usr/local/bin/irb
irb(main):001:0> 1.test
NoMethodError: private method `test' called for 1:Fixnum

(Even in 1.8.)

Until this problem is addressed, you can call a.performSelector(:test)  
as a workaround to make sure your Objective-C method will be called.

Laurent

On Mar 4, 2008, at 7:43 PM, Satoshi Nakagawa wrote:

> Hi,
>
> I tried to call a method in my ObjC class, then I got the 'private
> method' error.
> Even with a bridge-support file for the class, it remains the same.
>
> How can I use my ObjC class?
>
> @interface TestObject : NSObject
> - (void)test;
> @end
>
> #dir = NSBundle.mainBundle.resourcePath.fileSystemRepresentation
> #load_bridge_support_file dir + '/TestObject.bridgesupport'
>
> class AppController < NSObject
>   def awakeFromNib
>     a = TestObject.alloc.init
>     a.test
>   end
> end
>
> Revision: the latest trunk
> Project: http://limechat.net/macruby/ObjcTest.zip
>
> /Users/psychs/dev/macruby/ObjcTest/build/Release/ObjcTest.app/ 
> Contents/
> Resources/appcontroller.rb:7:in `awakeFromNib': private method `test'
> called for #<TestObject:0x10af580> (NoMethodError)
> 	from /Users/psychs/dev/macruby/ObjcTest/build/Release/ObjcTest.app/
> Contents/Resources/rb_main.rb:22:in `NSApplicationMain'
> 	from /Users/psychs/dev/macruby/ObjcTest/build/Release/ObjcTest.app/
> Contents/Resources/rb_main.rb:22:in `<main>'
>
> --
> Satoshi Nakagawa
>
> _______________________________________________
> 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