けいじゅ@日本ラショナルソフトウェアです. In [ruby-dev :14804 ] the message: "[ruby-dev:14804] Re: rational precision 対応 ", on Sep/18 21:47(JST) GOTO Kentaro writes: >ごとけんです >遅くなってすみませんです。 いえ. こちらこそ. 最近いろいろとせわしくて... >> RationalをPrecision対応しようと思っていますが、以下のような感じでよろしい? >> ##-- ここから. >> class Rational > include Precision >が必要ですね。(省略したのだと思いますが念のため) >> def Rational.induced_from(other) >> case other >> when Rational >> self >> when Integer >> Rational(other, 1) >> when Float >> o = other >> base = 1 >> while o != o.floor >> base *= 10 >> o *= 10 >> end >> Rational(o.floor, base) >> else >> super > >この super は無効です。陽に raise TypeError して下さい。 superでも動いているようですが? 陽に raise TypeError したほうがよいです? > raise TypeError, "failed to convert #{other.type} into Rational" > >> end >> end >> >> def prec(other_class) > >prec は include Precision で定義されるので再定義しなくても良 >いです。 うーん. 何か違うような... Precisionのなかでは module Precision def prec(other) other.induced_from(self) end end となっているだけなので, rational.prec(Integer) を呼ぶと, Integer.induced_from(rational) となり, そんなものしらんとなります... __ ..............................石塚 圭樹@日本ラショナルソフトウェア... ----------------------------------->> e-mail: keiju / rational.com <<---