Robert Klemme
4/20/2006 4:19:00 PM
Just Another Victim of the Ambient Morality wrote:
> Part of what added to my confusion, which was kindly pointed out by Dave
> Burt in another post on this thread, is that foo.bar = baz is invoking a
> method called "bar=". Again, I come from a C/C++ background, so it really
> looked like the method invocation was "bar" and it returned an object with
> the method "=" defined for it.
> Of course, now that I've been burned by it, I now know better and
> understand that assignment is not an overrideable operator.
> Thanks to everyone for the clarification...
Also it's important to note that Ruby's object references are different
from C++ references. In Ruby every variable (including method and block
parameters) holds a copy of the reference (like every variable was just
a C++ pointer variable and "call by value" only). So you never get into
a situation where changing a variable to point to something else has
side effects in other places of the program (e.g. the variable in the
calling scope points to another object, too).
(There are some cases that are treated specially under the hood but I
omit them on purpose because from the observed behavior there is no
difference.)
Kind regards
robert