I have a specific class C and I would like to overload some math operators.
I already overloaded +, i, *, and / so that I can do things like
a = C.new
b = C.new
a + b
a + 2
a + 2.0
To treat the last three cases, I am systematically testing for the type of the operand: is it C, Fixnum or Float, other possibilities are rejected. My first question is: is it the right way to do that?
Next I also want to be able to do
2.0 + A
How should I do it? Should I provide a conversion of some sort? Can these two problems be solved by the same method?
+,-,*,/,<,>, ...), if the operator calls a method. But there is no way to overload=in ruby.