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

**URL:** <https://www.ruby-forum.com/t/re-str1-str2-is-not-a-copy/74785>\
**Category:** Ruby\
**Created:** [November 7, 2006, 10:56am UTC](https://www.ruby-forum.com/t/re-str1-str2-is-not-a-copy/74785 "2006-11-07T10:56:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [November 7, 2006, 10:56am UTC](https://www.ruby-forum.com/t/re-str1-str2-is-not-a-copy/74785/1 "2006-11-07T10:56:20Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [November 7, 2006, 10:56am UTC](https://www.ruby-forum.com/t/re-str1-str2-is-not-a-copy/74785/2 "2006-11-07T10:56:24Z")

</div>

On 11/2/06, Gavin K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 🙂

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.
