Please do not top post.

On Fri, Oct 1, 2010 at 3:09 PM, Adriano Ferreira <adrfer / yahoo.com> wrote:
> Robert, I get the point. However it's important to notice that there's no=
 such
> thing as operator overloading in Ruby. Things like :+, :-, :*, etc, are j=
ust
> plain methods.

Adriano, operator "+" and all others are certainly overloaded (as in
many programming languages btw) because different implementations get
called depending on the left hand type.  Method #coerce is just a way
to get double dispatch working.

> You can achieve what you want by opening the Fixnum class and

I do not want something in particular (at least for the sake of this
thread) so I am not sure what you refer to.

> redefining the method :+. Important to say is that all instances of this =
will be
> affected as soon as you make the change.

This is precisely the reason to properly implement operators and
#coerce in new classes that should play nicely with existing classes.

> Eg:
>
> class Fixnum
> =A0def -(x)
> =A0 =A0self + x
> =A0end
> end
>
> puts 1 - 1 # =3D> 2

This is certainly not something I would want.

> Another tip: In Ruby, every expression returns a value, so there's no nee=
d to
> explicit the 'return'.

Yes, I know.  As far as I can see in my blog article there is no
"return" in the code.

Cheers

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/