Ruby でクラスが継承したクラスや include したモジュールの優先順位を調べる

クラスが継承したクラスや include したモジュールの優先順位は Module#ancestors で調べることができます。

module IncludedModule

end

module PrependedModule

end

class Super

end

class X < Super
    include IncludedModule
    prepend PrependedModule
end

X.ancestors
# => [PrependedModule, X, IncludedModule, Super, Object, Kernel, BasicObject]

メソッドsuper がどういう優先順位で呼ばれるのか調べるのに便利そう。