From: Tietew Date: 2004-04-16T14:57:39+09:00 Subject: [ruby-list:39569] Re: int/int in Ruby2? On Thu, 15 Apr 2004 14:04:48 +0900 In article [[ruby-list:39554] Re: int/int in Ruby2?] Itou-T15@mail.dnp.co.jp wrote: 括弧書きに反応 :) > (文字列の評価モードとかも、nullは空文字列とみなすとか、0扱いとか) nil.to_s == "" / nil.to_i == 0 / nil.to_f == 0.0 ですので,明示 的に変換してやれば今でも大丈夫です。 nil をいろいろなものと見なすのは止めた方がいいでしょう。Perl だ と演算子から型を決められますが (undef + undef == 0, undef . undef == "") Ruby で nil + nil は何になるの?とか。 それとは別にこんな変換メソッドがあってもいいかも。 class Object def to_bool; !nil?; end end class String def to_bool; !empty?; end end class Numeric def to_bool; self != 0; end end class IO def to_bool; !closed?; end end —[ Tietew ]—————————————————————————— メ : tietew@tietew.net / tietew@raug.net / tietew@masuclub.net ホペ: http://www.tietew.net/ Tietew Windows Lab. http://www.masuclub.net/ 鱒倶楽部 指紋: 26CB 71BB B595 09C4 0153 81C4 773C 963A D51B 8CAA