2011-05-01から1ヶ月間の記事一覧

instance_of?とis_a?の違い

instance_of?とis_a?の違いを、メモ。 以下のものを用いて実験 module Foo; end module Bar; end class Hoge include Foo end class Fuga < Hoge include Bar end fuga = Fuga.new instance_of? fuga.instance_of? Fuga #=> true fuga.instance_of? Hoge #=>…

&&とか||の返り値

&&と||の返り値に関して調べたので、メモ。 1 || 2 #=> 1 1 && 2 #=> 2 このようになるらしい。 というのも、 1 || 2 # この評価の時に、まずは、1をture/falseで評価するので、trueと評価され1が返る # && の評価も同様のロジック 直感的に、以下のように記…