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 Png genki on Sun 25 Jan 2009 at 20:47

Comments:

or Preview
Social Bookmarks
  • Delicious
  • B_entry1248
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ