From: matz@... (Yukihiro Matsumoto) Date: 1998-03-18T14:48:02+09:00 Subject: [ruby-list:7156] Re: undefined class switch まつもと ゆきひろです In message "[ruby-list:7155] undefined class switch" on 98/03/18, Keiju ISHITSUKA writes: |けいじゅ@日本ラショナルソフトウェアです. | |サブジェクトがわけ分からんですが(^^;;; 未定義変数(クラス)を含む可能性 |のあるswitchをエレガントに書く方法を教えて下さい. いやあ,ないでしょう.caseはその定義上whenで指定するオブジェ クトが定義されている必要がありますから,せいぜい全部をifで書 き,定義されていない可能性のあるものを defined?() で先にチェッ クする程度しか出来ないでしょう. def /(other) if other.kind_of? Bigfloat #break elsif other.kind_of?(Integer) || defined?(Rational) && other.kind_of?(Rational) self / Bigfloat(other) elsif other.king_of?(Float) Float(self) / other elsif defined?(Complex) && other.king_of?(Complex) Complex(self) / other else x, y = other.coerce(self) x / y end