From: Satoshi N. <sna...@in...> - 2007-12-09 23:14:29
|
I tried to solve this problem, but I cannot find a way to call the =20 original OCObjWrapper#method_missing. If you copy and paste the code =20= 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 =20= ##{self}" else raise e end end end alias_method_chain :method_missing, :example end end original =3D OSX::CIImage.imageWithContentsOfURL(OSX::NSURL.fileURLWithPath('/Users/=20= 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. 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 = #<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 gems. >> >> Any thoughts what might be going on or what I could try to get it >> working? >> >> Cheers, >> >> Marcus |