module LoudOld
def speak
super.upcase
end
end
class DogOld
def speak
"woof"
end
end
# *** before: ***
# include places a module BELOW the class in the ancestor chain, so it
# could not override a method the class already defines
class DogOld
include LoudOld
end
puts DogOld.new.speak # "woof", LoudOld#speak is never reached
# *** in version 2.0: ***
module Loud
def speak
super.upcase
end
end
class Dog
def speak
"woof"
end
prepend Loud # goes ABOVE the class in the ancestor chain
end
puts Dog.new.speak # "WOOF"
puts Dog.ancestors.first(2).inspect