継承順序の確認
メソッドのフックしたかったので、オーバーライドの順序調べてみる><
class C NAME = self.to_s def hook p NAME end end module M1 NAME = self.to_s def hook p NAME super end end module M2 NAME = self.to_s def hook p NAME super end end class S < C include M1 include M2 end S.new.hook #=>"M2" # "M1" # "C"
ってか、継承チェーンを返すメソッドがメタプログラミングRubyに有ったこと思い出すw
p S.ancestors #=>[S, M2, M1, C, Object, Kernel]
ん、覚えた
メタプログラミングRubyposted with amazlet at 10.11.03