けいじゅ@日本ラショナルソフトウェアです. In [ruby-list :9198 ] the message: "[ruby-list:9198] Re: induced_from ", on Aug/18 15:51(JST) GOTO Kentaro writes: >ごとけんです >あまり考えてなかったのですが、名前の統一の意味でしか >出来なさそうで、嬉しくないですね。 むむむ... 以下ぐらいの方が良くないですかね? module Precision def prec(klass) klass.induced_from(self) end def prec_i prec(Integer) end def prec_f prec(Float) end end class Complex include Precision def prec(klass) case klass when Integer, Float, Rational Complex(@real.prec(klass), @image.prec(klass)) when Complex self else super end end end prec本体を各クラスで定義するって方がわかりやすいと思います. >でも精度を特徴付けるモジュールはありそうだし、あった方が >クラスのインターフェイスの指針が解りよいと思うのですが。 私はそういう考え方は好きです. Ruby標準で: class Numeric include Precision def prec(klass) case klass when Integer to_i when Float to_f else super end end end としておけば, あとは, Matrix/Vector/Complexだけの対応で済みますね. あと, ちょっと危険ですが: module Precision def prec(klass) case klass when Integer to_i when Float to_f else klass.induced_from(self) end end def prec_i prec(Integer) end def prec_f prec(Float) end end でも良さそう. このばあい, Integer/Floatへの変換の時to_i, to_fでまずい場合はそのクラ スで対応しなくてはなりませんが. このぐらいのデフォルトの動作は許しても 良いかも. これだと, class Numeric include Presision end の追加とMatrix/Vector/Complexだけの対応で済みますね. いかがでしょう? __ ................................石塚 圭樹@日本ラショナルソフトェア... ----------------------------------->> e-mail: keiju / rational.com <<---