Name Tags, Not Suitcases

If you're new to programming, or you're used to a reference-oriented language like Java, this part will make all the sense in the world. It might be a problem if you're more used to C or C++.

As mentioned in Day 1, an equals sign (=) accomplishes reference, or assignment; in other words, it gives an object a name. But the name does not in any way contain the object. By way of illustration, let's use irb to make a String object and give it a simple name:

irb(main):01:0> a
						=
						"zif"
"zif"

What does it mean to assign b to a?

irb(main):02:0> b
						=
						a
"zif"

The correct way to think of this is that the string now has two names, a and b. It has not become two strings; no copy has been generated. We can try to alter a and b separately ...

Get Sams Teach Yourself Ruby in 21 Days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.