"Austin Ziegler" <halostatue / gmail.com> wrote/schrieb <9e7db9110701271150i30ae8023h27dfcae386a3629e / mail.gmail.com>:
> The simplest way to remember this is that variables in Ruby aren't
> chunks of memory.
Or: they are a chunk of memory, but the only kind of value they can
contain is a reference to an object. A variable is not such an object,
i.e. there are no references to variables.
Ruby
~~~~
Var. obj.-id object
+---+ +---+
a --->| | | |
| |--->| |
b --->| | | |
+---+ | |
| |
| |
| |
| |
+---+
If one passes a value, always an object id will be passed.
If one just uses variable ``a'', it will always go through the
automatial indirection of the object id. If ``a'' and ``b'' go through
the same indirection (using the same object id), then state can be
manipulated mutually.
C
~
Var. memory
+---+
a --->| |
| |
b --->| |
| |
| |
| |
| |
| |
+---+
If one passes a value, the memory will be copied. Then state can no
longer be manipulated.
Regards
Thomas