25th
Sun
継承関係を比較する演算子
rubyのクラス同士の継承関係を比較する演算子についてのメモ。
1 >> class Foo;end 2 >> class Bar<Foo;end 3 >> class Baz<Foo;end 4 >> [Foo < Bar, Bar < Foo, Foo > Bar, Bar > Foo] 5 => [false, true, true, false] 6 >> Foo <=> Bar 7 => 1 8 >> Foo <=> String 9 => nil 10 >> Bar <=> Foo 11 => -1 12 >> Bar <=> Baz 13 => nil
また、以下のようにモジュールのinclude関係も取得出来ます。
1 >> module Goo;end 2 >> class Foo;include Goo end 3 >> Foo < Goo 4 => true 5 >> Foo > Goo 6 => false 7 >> Goo < Foo 8 => false 9 >> Goo > Foo 10 => true
posted by
genki
on Sun 25 Jan 2009
at 20:47