From: christophe mckeon Date: 2006-06-21T06:32:43+09:00 Subject: Re: binary operators, coerce, and non numeric types ok i hadn't fully grokked coerce, and have found a solution. just incase anybody is interested: class X def + other bin_op other, :+ end def ** other bin_op other, :** end def - other bin_op other, :- end def / other bin_op other, :/ end def bin_op other, op if @coerced @coerced = false BinOp.new other, self, op else BinOp.new self, other, op end end def coerce other @coerced = true [self,other] end end class BinOp def initialize x,y,op @x, @y, @op = x, y, op end def to_s "BinOp #@x #@op #@y" end end x = X.new puts x + 3 puts 3.0 + x puts 2 - x puts x - 10 puts 23 ** x puts 2.99 / x puts x / -1 cheers, _c -- Posted via http://www.ruby-forum.com/.