From: Jonathan P. <jp...@dc...> - 2005-04-28 07:57:50
|
On 26 Apr 2005, at 16:08, kimura wataru wrote: > I'm sorry my reply is too late. No problem at all. > It's cool! If you allow, I will add kvc_accessor to RubyCocoa. Yes, please do. > btw, Module#method_added enables to hook method definition. Following > code reverts a wrapper of a setter when the setter is overrided. > [snip code] Ah! Looks good. I will try it out. I've attached a patch to this message that extends the base Ruby-Cocoa bridge class methods. addRubyMethod_withType allows creation of an actual ObjC method corresponding to a ruby method. This means that key-value coding will be able to find the actual method when it does a lookup. This could be used to define real accessor methods (therefore avoiding the valueForUndefinedKey hook), or for implementing array accessors (which have no such hook). For example: def kvc_array_accessor(*args) kvc_accessor(*args) args.each do |v| n = v.to_s n[0..0] = n[0..0].upcase self.addRubyMethod_withType("countOf#{n}".to_sym,"i4@8:12") self.addRubyMethod_withType("objectIn#{n}AtIndex_".to_sym,"@4@8:12i16") self.addRubyMethod_withType("insertObject_in#{n}AtIndex_".to_sym,"@4@8: 12@16i20") self.addRubyMethod_withType("removeObjectFrom#{n}AtIndex_".to_sym,"@4@8: 12i16") # ... I've attached an updated version of ObjcID that has the full implementation of this method. Thanks Jonathan |