From: GOTO Kentaro Date: 2001-09-18T21:47:32+09:00 Subject: [ruby-dev:14804] Re: rational precision 対応 ごとけんです From: keiju@ishitsuka.com (Keiju ISHITSUKA) Subject: [ruby-dev:14768] rational precision 対応 Date: Mon, 10 Sep 2001 21:13:39 +0900 > けいじゅ@日本ラショナルソフトウェアです. > > 主にごとけんさんへ. 遅くなってすみませんです。 > 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 して下さい。 raise TypeError, "failed to convert #{other.type} into Rational" > end > end > > def prec(other_class) prec は include Precision で定義されるので再定義しなくても良 いです。 -- Gotoken