In C++, one thing that is certain is that all variables passed into functions and all return values are actually copies. Therefore, the functions can't manipulate their arguments directly. As everyone knows, the easiest way to get this effect is to pass in by reference. This way a copy is not made; the actual variable is passed in, allowing direct modification. A similar idea can be used with return values or even without a function at all.
The question is, how exactly does ruby behave in this respect? I haven't quite figured out what the rules are. It appears that Fixnum and basically every user-made object are always passed by value, and can not reference each other. However, arrays seem to be passed into functions by reference, and returned by value, though the objects they contain are copied.
At first, I thought variables were always pointers, and things such as a = b meant that if you change a, you change b. It seems now that this is in fact never the case. So that brings me to my second question: what are the purpose of the methods dup and clone? I thought they would be useful if you needed to assign copies rather references, but it seems that objects are copied by default when assigned. Can someone please explain this to me?
···
---------------------------------
Yahoo! FareChase - Search multiple travel sites in one click.