From: "Mauricio Fernández" Date: 2004-03-19T20:14:58+09:00 Subject: Re: calling outer-scope method of same name On Fri, Mar 19, 2004 at 11:27:26AM +0900, 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. > > def x > puts "Top level" > end > > class A > def x > puts "A#x" > end > end > > class B < A > def x > super > end > end > > B.new.x # => A#x > > > So it's not a reliable way of reaching back to the top level. > It's still better than Kernel.x in the sense that 'self' is the right one and it will work with private instance methods. The following solves the problem completely IMHO class Object def my_call(klass, method, *args, &block) klass.instance_method(method).bind(self).call(*args, &block) end end def spleen puts "Object#spleen" end class A def spleen puts "A#spleen" end end class Blah < A def spleen super # uses A's puts "now Object's" my_call(Object, :spleen) # uses Object's end end Blah.new.spleen batsman@tux-chan:/tmp$ ruby dispatch.rb A#spleen now Object's Object#spleen One could try to find a better syntax for that, maybe :Object.call.spleen or :Object[:spleen].call but I'm not so fond of them (implementing this sort of things is fun though :). -- Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com I am NOT a kludge! I am a computer! -- tts