25th Sun
継承関係を比較する演算子
rubyのクラス同士の継承関係を比較する演算子についてのメモ。
ruby>>
class Foo;end
class Bar<Foo;end
class Baz<Foo;end
[Foo < Bar, Bar < Foo, Foo > Bar, Bar > Foo]
=> [false, true, true, false]Foo <=> Bar
=> 1Foo <=> String
=> nilBar <=> Foo
=> -1Bar <=> Baz
=> nil
<<--
また、以下のようにモジュールのinclude関係も取得出来ます。
ruby>>
module Goo;end
class Foo;include Goo end
Foo < Goo
=> trueFoo > Goo
=> falseGoo < Foo
=> falseGoo > Foo
=> true
<<--
posted by
genki on Sun 25 Jan 2009 at 20:40 with 0 comments