From: matt@... (matt neuburg) Date: 2006-12-09T11:05:11+09:00 Subject: Re: Array changing after concat function Logan Capaldo wrote: > On Fri, Dec 08, 2006 at 05:35:09AM +0900, matt neuburg wrote: > > WKC CCC wrote: > > > > > unknown wrote: > > > > WKC CCC wrote: > > > > > > > >> > > > >> count = count + 1 > > > >> end > > > >> > > > >> puts one.inspect > > > > > > > > Array.new(array) copies the *array* but it does not copy its *elements*. > > > > So tempArr[0] is another name for the very same object as one[0], and so > > > > forth. m. > > > > > > If they are referring to the same object, why is it when > > > > > > tempArr = Array.new(one) > > > one.clear > > > > > > results in tempArr still having the values originally assigned to array > > > one? > > > > Reread what I said. I didn't say that tempArr and one refer to the same > > object; I said that tempArr[0] and one[0] (and so on) refer to the same > > object. > > > > Think of it this way. Items in an array are dogs. Arrays are people > > holding leashes. Anyone can attach a leash to a dog. So I (tempArr) can > > have a leash on Fido, and so can you (one). If you let go of your leash > > (one.clear), Fido is still Fido; you just don't have a leash on him. But > > if you cut off one Fido's legs (modify one[0]), that leg on my Fido > > (tempArr[0]) is also cut off, because they are the same Fido. > > > > m. > > > That is the most disturbed, and yet apt analogy ever Clearly you've never read any of my books. > Mind if I quote you? Woof! (That means "Be my guest.") m. -- matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/ Tiger - http://www.takecontrolbooks.com/tiger-customizing.html AppleScript - http://www.amazon.com/gp/product/0596102119 Read TidBITS! It's free and smart. http://www.tidbits.com