From: keiju@... (ÀÐÄͷ½¼ù ) Date: 1996-10-30T17:00:38+09:00 Subject: [ruby-list:946] Rational[coerce(Re: ruby 0.99.3-961030 available) ] けいじゅ@SHLジャパンです. In [ruby-list :00943 ] the message: "[ruby-list:943] coerce(Re: ruby 0.99.3-961030 available) ", on Oct/30 16:11(JST) matz@caelum.co.jp (Yukihiro Matsumoto) writes: >普通の算術演算子はこうなっています(こうなりました). > > def + other > case other.type > when "Fixnum" > : > else > x, y = other.coerce(self) > return x + y > end > end > >ですからRationalの場合 > > def coerce other > if other.type == "Float" > return other, Float(self) > else > super > end > end > >とすれば問題は解決できるのではと考えました. なるほど. 分かりました. 試してみます. この方法だと, 複数の非既存クラス間の調整が微妙ですが, 以前とは違って全 く実現不可能ではなくなりましたね. この間に直してもらったと思ったのですが... class Rational < Numeric def Rational.new(a, b) : end を定義しても, q = Rational.new(1, 2) を実行すると undefined method new が出ます. __ ..........................................石塚 圭樹@SHLジャパン(株)... ------------->アドレス変わりました!! e-mail: keiju@shljapan.co.jp <----