![]() |
|
#1
|
|||
|
|||
|
Hallo.
Ich hab ein Verständnisproblem bei folgendem Code. module BikeMethods def info puts "I'm a Bike." end end class Bike include BikeMethods end class Car def info puts "I'm a Car." end end class Vehicle < Car include BikeMethods def info super end end v = Vehicle.new v.info # returns "I'm a Bike." Da Vehicle von Car erbt sollte doch super() die Methode info() von Car aufrufen. Warum ist das nicht so? lg michi |
|
|
||||
|
||||
|
|
|
#2
|
|||
|
|||
|
On 14.10.2009 17:38, Michael Maier wrote:
> Hallo. > > Ich hab ein Verständnisproblem bei folgendem Code. > > module BikeMethods > def info > puts "I'm a Bike." > end > end > > class Bike > include BikeMethods > end > > class Car > def info > puts "I'm a Car." > end > end > > class Vehicle < Car > include BikeMethods > > def info > super > end > end > > v = Vehicle.new > v.info # returns "I'm a Bike." > > > Da Vehicle von Car erbt sollte doch super() die Methode info() von Car > aufrufen. > Warum ist das nicht so? Weil BikeMethods dazwischen hängt. Gib mal Vehicle.ancestors aus, dann siehst Du das. Ciao robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ |
|
|
|
|