[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Gavin Kistner

11/2/2006 9:17:00 PM

From: Joe Ruby 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 :)