On Tue, Jun 21, 2011 at 11:30:46PM +0900, Robert Klemme wrote: > 2011/6/21 Ondナ册j Bテュlka <neleai / seznam.cz>: > > On Tue, Jun 21, 2011 at 04:06:05PM +0900, Robert Klemme wrote: > >> 2011/6/18 Ondナ册j Bテュlka <neleai / seznam.cz>: > >> > >> > Are there reasons other than historic that coerce returns converted pair instead > >> > returning directly result of operation like > >> > def coerce2(x,op) > >> > x.to_foo.call(op,self) > >> > end > >> > >> http://blog.rubybestpractices.com/posts/rklemme/019-Complete_Numeric_Class.html > > Why should Hexnum.new(1)+0.5==Hexnum.new(1)+0.6 > > ? Well if you write you should be sure that you did basic things rigth. Skimming through article there following issues initialize that should be def initialize(val); @i=val.to_i; end Which is simpler and more consistent with ruby type system to_hex for every object breaks assumtion that if object responds to to_foo then it should be convertible to foo Hexnum.to_s should be @i.to_s(16) + and * also have useless cases and implemented in different way. Now coerce implemented as [HexNum.new(o.to_int), self] just asks for problems. For example Hexnum.new(2)+0.5== Hexnum.new(2)+0.6 and 0.5+0.6+Hexnum.new(2)!=0.5+Hexnum.new(2)+0.6 A star wars satellite accidently blew up the WAN.