From: Sander Land Date: 2006-09-13T04:31:17+09:00 Subject: Re: inheritance and super function On 9/12/06, Surendra Singhi wrote: > Now, in the function test in Class C, I want to call the test method defined > in class A, by passing B's test method. > > How can I do this, just using plain 'super' doesn't work? Is it possible to do > this? Use instance_method and bind. module Kernel def super_n(n=1) self.class.ancestors[n].instance_method(caller.first[/`(.*)'/][1..-2]).bind(self).call end end class C < B def test puts "I am C" A.instance_method(:test).bind(self).call self.class.superclass.superclass.instance_method(:test).bind(self).call self.class.ancestors[2].instance_method(:test).bind(self).call super_n(1) super_n(2) end end C.test.new => I am C I am A I am A I am A I am B I am A