Rubyでクラスの親クラスを取得するには、Class#superclassを使えばよいという事を知った。 なので、BasicObjectまで遡れば継承している全ての親クラスを取得することができる。
`\
ruby class Foo end
class Bar < Foo end
class Hoge < Bar end
class Class def all_superclass def recur(c, a) return !c.superclass ? a : recur(c.superclass, a.push(c.superclass)) end recur(self, []) end end
p Hoge.all_superclass `\
実行結果はこう。
sh
$ ruby ./get_all_superclass.rb
[Bar, Foo, Object, BasicObject]
任意のクラスを継承しているか判別するのに使えると思う。