Alex Gutteridge
8/21/2007 6:58:00 AM
On 21 Aug 2007, at 15:12, Dan wrote:
> I understand that ruby being strongly typed means you can only do
> "sensible"
> things with the types you are working with. However, aren't the
> examples
> above pretty much equivalent? or is it a precedence thing? Trying
> to answer
> my own question is it because the "*" operator for a Fixnum only
> accepts
> another Fixnum/Bignum, while the "*" operator for a String only
> allows a
> Fixnum, because it sure doesn't let you do String * String (and why
> would
> you really).
To clarify my previous answer, the important thing is to realise that
most 'operators' in Ruby are just methods that look funny. So
3 * 2
Is just another way of writing
3.* 2
or
3.send(:*,2)
And hence 'foo' * 2 is very different to 2 * 'foo' in terms of the
underlying method that is called.
Alex Gutteridge
Bioinformatics Center
Kyoto University