Fixnum#+ - . :
class Fixnum
def +(other)
if Fixnum === other
else
n1, n2= other.coerce(self)
return n1+n2
end
end
end
coerce . , , 42 + 3.141. . String, .
class String
def coerce(other)
coerced= case other
when Integer
self.to_i
when
self.to_f
end
return coerced, other
end
end
23 + "42"
0.859 - "4"
. coerce "23" + 42 . String#+ .
+ Fixnum, Integer. Fixnum Bignum , .