How well do you know your Ruby inheritance chain? What is the output of the following script?
class Parent
def identify
puts "Parent"
end
end
class Child < Parent
def identify
puts "Child"
super
end
end
module FirstMixin
def identify
puts "FirstMixin"
super
end
end
module SecondMixin
def identify
puts "SecondMixin"
super
end
end
Child.send :include, FirstMixin
Child.send :include, SecondMixin
my_child = Child.new
class << my_child
def identify
puts "Meta"
super
end
end
my_child.identify
(scroll down for the answer)
The output:
Meta
Child
SecondMixin
FirstMixin
Parent
First the meta class, then the class itself, then the included modules (most recently included first), and then the superclass.