From: Jonathan P. <jp...@dc...> - 2005-08-23 07:50:54
|
On 23 Aug 2005, at 2:12, Steven Arnold wrote: > > Here's a complete program, runnable on the command-line, that will > break. If you comment out the "private" line and the attr_accessor > line, it will work. It does not have the same problem with public > or protected attributes! > > Weird...... Any thoughts? I don't think the attr_accessor is relevant. What's happening is this: 'private' with no arguments makes all following methods private. The getHash method is private. When you call it from outside the class, ruby fails to find the method and invokes method_missing if defined. If it wasn't, you'd get something like: private method `getHash' called for #<Y:0x4fce88> (NoMethodError) Since method_missing is defined by RubyCocoa, it does the method lookup, which ignores the method protection. Solution: add 'public' sometime after 'private' in order to reset the protection. Hope that makes sense. Jonathan |