From: toyofuku@... Date: 1998-03-27T02:58:55+09:00 Subject: [ruby-dev:1950] Re: new coerce 豊福@パパイヤです。 けいじゅさん > 新coerce案を検討します. > [新案2] > 呼出側では直接coerceを呼ぶのではなくて演算を代わりにやってくれる以下の > ような別メソッドを導入し: ... > [新案3] > もう1つの案は, coerceをやめてdelegete_opだけにしてこっちを再定義するよ > うにするというのもです. ... 私が self.coerce(other, op) -> (other', self', op') 案 の前に考えていたのが class Matrix def coerce(other, meth) ... if (other側で計算できそうにないとき) こっちで計算して答を返す else # other側で計算できそうなとき ... return other', self' end ... end class Fixnum def *(other) case other ... else x, y = other.coerce(self, :*) if (答だけが返ってきたとき) return 答 else return x * y end end end end という[新案3]を中途半端にしたようなものでした。 > [新案3] ... > でも, Matrixみたいな場合はそうでも, 以下のような単純な場合は ... > def coerce(other, op) > if Complex.generic?(other) > return Complex.new(other), self ... > で済むのに ... > def coerce(other, op) > if Complex.generic?(other) > Complex.new(other).send(op, self) > と書かなくてはならなくなって, かえって面倒ですね... このくらいの面倒なら私は許せる範囲ですが、既存の部分の 書き換えも考えると面倒でしょうね。 --- 豊福@パパイヤ unbound@papaya.juice.or.jp toyofuku@juice.or.jp