From: Gary Wright Date: 2010-02-06T02:59:23+09:00 Subject: Re: Inheritance related problem On Feb 5, 2010, at 10:33 AM, Xavier Noëlle wrote: > 2010/2/5 R. Kumar : >> If you are saying that aM() forces a call to the parent's m() and of >> course you have inherited from Father, then yes. > > Yes, my mistake, I forgot the "public Father". > >> def aM >> super.m >> end > > Yes, indeed, but what if I need to call a specific parent's method ? > Say Parent > Child > Grandchild. Is it possible to Parent::m in > Grandchild (other than super.super.m(), if it works :-)) ? That idiom isn't well supported in Ruby, but it is possible in an awkward sort of way: $ cat sample.rb class Parent def foo(*args) puts "Parent:foo: #{args.inspect}" end end class Child < Parent def foo(*args) super puts "Child:foo: #{args.inspect}" end def parent_foo(*args) Parent.instance_method('foo').bind(self).call(*args) end end $ irb >> load 'sample.rb' => true >> Parent.new.foo(1,2,3) Parent:foo: [1, 2, 3] => nil >> Child.new.foo(4,5,6) Parent:foo: [4, 5, 6] Child:foo: [4, 5, 6] => nil >> Child.new.parent_foo(7,8,9) Parent:foo: [7, 8, 9] => nil >> Gary Wright