Pit Capitain wrote:

> Adam Wildavsky schrieb:
>> I'd like to call a particular inherited method rather than the one in 
>> my immediate ancestor. For instance
>           Object.instance_method( :to_s ).bind( self ).call

For the fun of it I've taken this to the extreme and called it 
superjump: (It 'jumps' over one or more method in the inheritance chain)

# Like super this calls methods from the inheritance chain which this
# method is replacing. However this version jumps over one or more
# methods in the inheritance chain. It is used like this:
#
#   class X
#     def it; p "X#it"; end
#   end
#
#   class Y < X
#     def it; p "Y#it"; end
#   end
#
#   class Z < Y
#     def it
#       p "Z#it"
#       superjump
#     end
#   end
#
#   Z.new.it # outputs "X#it", "Z#it"
#
# Be careful. This method can't automatically pass the arguments of the
# caller like super does. You'll have to manually supply them.
def superjump(gap, *args)
   method_name = caller[0][/in `(.*?)'/, 1].intern
   klass = self.class.ancestors[1 + gap]
   klass.instance_method(method_name).bind(self).call(*args)
end

Regards,
Florian Gross