Hi...
So, I am writing a ruby program that produces object code in another
language for any mathmatical and logical operations you do on my
objects. And within my system, it also makes sense to mix my objects
with integers. So I use the coerce mechanism to achieve what I want.
It works.
But I found an odd thing: coerce doesn't seem to get called for >>,
<<, &, | or ^.
So I have to do something like this for each of these:
class Fixnum
alias_method :_lshift, :<<
def << (n)
if (n.kind_of?(Numeric))
_lshift n
else
$p.write_num(self)
EtaImmediate.instance << n
end
end
end
I wonder if anyone knows why I have to do this for these operators?
And, as an aside, I also want to overload || and &&... (and !=, but
I've found a way around that)... I wonder what the reasoning behind me
not being able to do this is?
Regards,
S.Sykes