Re: str1 = str2 is not a copy?!?

From: Joe R. MUDCRAP-CE
[snip]

WHY is var line getting changed by operations on var base_name? Isn’t
‘base_name = line’ supposed to create a copy? ‘=’ in this
case seems to be acting like an alias or something.

Variables point to objects, they do not “hold” or “contain” them.

What you are suggesting is that:
me = Person.new
would create a new Person object, and then duplicate it before assigning
to ‘me’, or that:
my_really_long_array_name = [ 1, 2, 3 ]
short_name = my_really_long_array_name
would result in two different copies of the array.

That’s the opposite of how it works :slight_smile:

On 11/2/06, Gavin K. [email protected] wrote:

me = Person.new
would create a new Person object, and then duplicate it before assigning
to ‘me’, or that:
my_really_long_array_name = [ 1, 2, 3 ]
short_name = my_really_long_array_name
would result in two different copies of the array.

That’s the opposite of how it works :slight_smile:

But is oddly enough almost exactly how it works in PHP. And thus one of
the
major battles PHP has had between versions has been about the semantices
of
reference, and pass/call by reference. I’m GLAD Ruby functions this
way, as
it removes a lot of complexity dealing with references.