From: Mark Hubbart Date: 2004-03-19T14:52:29+09:00 Subject: Re: calling outer-scope method of same name On Mar 18, 2004, at 6:27 PM, David A. Black wrote: > My only problem with the 'super' approach is that it doesn't really > execute the top-level version of the method; it executes the next > version up in the method search path, which may or may not be the > top-level version. > So it's not a reliable way of reaching back to the top level. This works: def quux(n) "q#{"u"*n}x" end class Foo def quux(n) "foo's q#{"u"*n}x" end end class Bar < Foo def quux(n) Object.new.quux(n) end end quux 5 #=> "quuuuux" Foo.new.quux 5 #=> "foo's quuuuux" Bar.new.quux 5 #=> "quuuuux" Just instantiate an Object, and call the method. Or, you can rebind the actual method. That would be better if performance is an issue, I think: def maybe? "yes" end Foo.new.maybe? #=> "yes" class Foo def maybe? "no" end end Foo.new.maybe? #=> "no" m=method "maybe?" #=> # Bar.instance_eval{define_method :maybe?, m} maybe? #=> "yes" Foo.new.maybe? #=> "no" Bar.new.maybe? #=> "yes" --Mark