通常のメソッドルックアップパス、つまりを理解していますclass, superclass/module, all the way up to BasicObject
。シングルトンバージョンのチェーンにも当てはまると思いましたが、メタチェーンにモジュールをミックスインした場合はそうではないようです。このモジュールをVehicleの固有クラスに含めたときに、次の例でシングルトンバージョンの代わりにAutomobile
モジュールのメソッドが呼び出される理由を誰かが説明していただければ幸いです。banner
module Automobile
def banner
"I am a regular method of Automobile"
end
class << self
def banner
"I am a class method of Automobile"
end
end
end
class Vehicle
def banner
"I am an instance method of Vehicle"
end
class << self
include Automobile
def banner
puts "I am a class method of Vehicle"
super
end
end
end
class Car < Vehicle
def banner
"I am an instance method of Car"
end
class << self
def banner
puts "I am a class method of Car"
super
end
end
end
puts Car.banner
# I am a class method of Car
# I am a class method of Vehicle
# I am a regular method of Automobile