F. Senault
5/20/2009 8:00:00 AM
Le 19 mai à 21:29, Marc-antoine Kruzik a écrit :
> 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".
> 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 ?
As others said, refactor, there's a problem with you inheritance logic.
That being said, you could work in the Father class like this to obtain
the wanted result :
class Father < Grand_father
def say_hello
super
puts "Father : Hello" unless self.is_a? Son
end
end
Fred
--
First, there was the command-line interface. This allowed users to type
a line of text representing a "command", press the RETURN key, and
receive a response like "0x38754: ERROR_NOTEXT_PETUNIA". Thanks to this
handy software tool, the suicide rate rose almost overnight. (D Barrett)