I've seen how to overload +
and *
in Ruby, so that
my_obj + other
calls my_obj.+(other).
In Python, you do this with __add__
, and there's a corresponding __radd__
for overloading other + my_obj
. Is there really no equivalent right-sided addition/multiplication in Ruby, and does that make it necessary to redefine +
for each potential class of other
?
In brief: say I have an object X
which belongs to some new class defined by me. It's easy to write code for X + 5
, but it seems that in order to handle 5 + X
I'd need to redefine Fixnum.+
. Is this true?