From: Robert Klemme Date: 2009-05-20T05:45:03+09:00 Subject: Re: Super super ? On 19.05.2009 21:29, Marc-antoine Kruzik wrote: > Hello, I'm looking for informations about "super". > > I have 3 classes : grandfather, father, and son. > And they all have a method named "say_hello". > > > > [code] > class Grand_father > def say_hello > puts "Grand Father : Hello" > end > end > > class Father < Grand_father > def say_hello > super > puts "Father : Hello" > end > end > > class Son < Father > def say_hello > super > puts "Son : Hello" > end > end > [/code] > > s = Son.new > s.say_hello > Grand Father : Hello > Father : Hello > Son : Hello > > But now, I would that Son didn't call Father, but directly Grand_father. > > s.say_hello > Grand Father : Hello > Son : Hello > > How could I do that ? You can do class Son < Father def say_hello Grand_father.instance_method(:say_hello).bind(self).call puts "Son : Hello" end end However, as the weird construction indicates something might be wrong with this kind of design. If you assume that the method actually had side effects on the instance's state and you leave out one class in the chain you likely end up with an instance in an inconsistent state. In that case the design probably needs some work. Btw, if Father does not define say_hello super will automatically call Grand_father's method. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/