From: Gavin Kistner Date: 2006-11-04T09:20:21+09:00 Subject: Re: str1 = str2 is not a copy?!? From: Gregory Brown [mailto:gregory.t.brown@gmail.com] > > array = ['you', 'loose.'] > > a, b = array > > > > p [a,b] > > p array > > > > b = 'win!' > > p array # Doh!! > > > > x = array ; x[1] = 'win!' > > p array # array has been changed > > I get the point of this example, but it's worth noting that you can > change the array via b if you just use String#replace Wording like that promotes dangerous mental models, IMO. *NOTHING* about the array itself changes. It still refers to exactly the same objects as it did before. It's just that you happened to have one of the objects that it refers to change. Consider the example: Person = Struct.new( :name, :age ) gavin = Person.new( 'Gavin', 33 ) lisa = Person.new( 'Lisa', 32 ) people = [ gavin, lisa ] someone = people[ 0 ] someone.age = 600 In the above, I am changing the 'Gavin' person to have a new age. Because the first element in the 'people' array is that same object, you might say that the array 'changed'. It would be better not to think of it this way, however. The array STILL refers to Gavin and Lisa.