From: Jonathan P. <jp...@dc...> - 2005-08-22 20:20:34
|
On 22 Aug 2005, at 17:45, Steven Arnold wrote: > > When I call self.getFormValues, I do not get back a Ruby Hash, but > rather a Cocoa NSCFDictionary. Right before the return, it's a > hash....but when it gets back, it's an NSCFDictionary. Could you include the exact code you're using when calling getFormValues? The behaviour ought to be as you're hoping, but it won't if the method call is going via the Objective C bridge. The effects you're seeing should only occur if the method call goes via the objective-c bridge. For normal method calls directly on a ruby object when the target method is implemented in ruby, it shouldn't get involved. The bridge is implemented by hooking into method_missing, so it gets involved when the method can't be found in ruby. You can force the bridge to get involved by prefixing the method name with 'oc_', which is a special case. Since a method with this name doesn't exist, the Objective C bridge will get invoked, and it strips the 'oc_' prefix. It converts arguments and return values to and from Objective C, makes the Objective C call, which ends up getting routed back to the ruby code. For example: class X < OSX::NSObject def getHash {} end def me self end def selfGetHash self.getHash end end x = X.alloc.init x.getHash #=> {} x.me #=> #<X:0x812db2 class='X' id=0x12a02f0> x.selfGetHash #=> {} x.oc_me #=> #<X:0x812db2 class='X' id=0x12a02f0> x.oc_getHash #=> #<OSX::OCObject:0x80e596 class='NSCFDictionary' id=0x12a9f30> x.oc_selfGetHash #=> #<OSX::OCObject:0x80d844 class='NSCFDictionary' id=0x12abc30> Can you confirm that the above code behaves as expected? Thanks Jonathan |