From: Satoshi N. <sna...@in...> - 2007-12-09 23:41:24
|
Finally I have found a way. Just include OCObjWrapper. It seems due to an execution order. require 'osx/cocoa' require 'rubygems' require 'active_support' module OSX class CIImage include OCObjWrapper def method_missing_with_example(sym, *args, &block) method_missing_without_example(sym, *args, &block) end alias_method_chain :method_missing, :example end end original =3D OSX::CIImage.imageWithContentsOfURL( OSX::NSURL.fileURLWithPath('/Users/crafterm/Desktop/=20 leaves_desktop.jpg')) p original.extent.size -- Satoshi Nakagawa On 2007/12/10, at 8:13, Satoshi Nakagawa wrote: > I tried to solve this problem, but I cannot find a way to call the > original OCObjWrapper#method_missing. If you copy and paste the code > in oc_wrapper.rb, it works well. > Does anyone know a better way? > > > require 'osx/cocoa' > require 'rubygems' > require 'active_support' > > module OSX > class CIImage > def method_missing_with_example(sym, *args, &block) > method_missing_without_example(sym, *args, &block) > end > > def method_missing(mname, *args) > m_name, m_args, as_predicate =3D analyze_missing(mname, args) > begin > result =3D self.ocm_send(m_name, mname, as_predicate, *m_args) > rescue OCMessageSendException =3D> e > if self.private_methods.include?(mname.to_s) > raise NoMethodError, "private method `#{mname}' called for > ##{self}" > else > raise e > end > end > end > > alias_method_chain :method_missing, :example > end > end > > original =3D > OSX::CIImage.imageWithContentsOfURL(OSX::NSURL.fileURLWithPath('/=20 > Users/ > crafterm/Desktop/leaves_desktop.jp')) > p original.extent.size > > -- > Satoshi Nakagawa > > On 2007/12/10, at 7:33, Satoshi Nakagawa wrote: > >> Hi, >> >> RubyCocoa defines Object.method_missing to realize a transparent >> bridge between Ruby and Cocoa. If you redefine method_missing of a >> class, then=10=10=10=10=10=10 the class won't respond to any ObjC = methods. =20 >> That's >> why alias_method_chain doesn't work. >> >> -- >> Satoshi Nakagawa >> >> On 2007/12/09, at 10:47, Marcus Crafter wrote: >> >>> Hi All, >>> >>> Hope all is going well! >>> >>> I'm trying to extend method_missing on OSX::CIImage using >>> alias_method_chain and are having trouble getting it to work, here's >>> an example to demonstrate it: >>> >>> require 'rubygems' >>> require 'active_support' >>> require 'osx/cocoa' >>> >>> module OSX >>> class CIImage >>> def method_missing_with_example(sym, *args, &block) >>> method_missing_without_example(sym, *args, &block) >>> end >>> >>> alias_method_chain :method_missing, :example >>> end >>> end >>> >>> original =3D >>> OSX::CIImage.imageWithContentsOfURL(OSX::NSURL.fileURLWithPath('/ >>> Users/ >>> crafterm/Desktop/leaves_desktop.jpg')) >>> puts original.extent.size >>> >>> When I run this I get: >>> >>> NoMethodError: undefined method =91extent=92 for =20 >>> #<OSX::CIConcreteImage: >>> 0x117248c> >>> >>> If I comment out the call to alias_method_chain I get the expected >>> result: >>> >>> #<OSX::CGSize:0x1173710> >>> >>> Somehow alias_method_chain breaks it. This is using Ruby & RubyCocoa >>> as per a default install of Leopard, Rails 2.0.1 active support =20 >>> gems. >>> >>> Any thoughts what might be going on or what I could try to get it >>> working? >>> >>> Cheers, >>> >>> Marcus > > > = ------------------------------------------------------------------------- > SF.Net email is sponsored by: > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://sourceforge.net/services/buy/index.php > _______________________________________________ > Rubycocoa-talk mailing list > Rub...@li... > https://lists.sourceforge.net/lists/listinfo/rubycocoa-talk |