Category talk:Ruby: Difference between revisions

What does this really mean?
No edit summary
(What does this really mean?)
Line 68:
:Ruby, Python, Scheme, Java (when talking about objects), etc.; all of these pass by value. People who argue against pass by value seem to have a different idea of what is being passed. They think that you are "passing" an "object". But that fact is, in all these languages, the values in the language are "references" (or pointers, or whatever you call them; the idea is the same: there is a level of indirection). You can never manipulate an "object" directly in these languages; you can only do it through references (you can see that values are references by assigning one variable to another and seeing that they point to the same object, hence a reference is copied, not the object). So when you are passing stuff, the values you are passing are the references, and those references are copied. In a pass-by-reference language, you would be able, in the function, to change the thing that is passed -- the reference -- in the calling scope; but you can't in Ruby; you can verify this by checking x.object_id to see that the reference still points to the same object.
:People tend to point out that if these objects are mutable (e.g. String in Ruby), then it is possible to use its mutation methods to mutate its internal state in a way that is visible to other people who have a reference to the same object; but this is irrelevant. Because it is not the object that is being passed -- it is the reference. We can separate out the mutation issue by using an object type that is not mutable, e.g. take an integer or float or boolean in Ruby, and passing it; see that you cannot affect it in the calling scope; whereas in a true pass-by-reference language, you always can. --[[User:Spoon!|Spoon!]] 07:01, 11 August 2011 (UTC)
::That said, note that this point of view is that you cannot pass an object to a method. --[[User:Rdm|Rdm]] 12:33, 11 August 2011 (UTC)
6,951

edits