WKC CCC <wai-kee.chung / uk.bnpparibas.com> wrote:

> Can someone shed some light on this problem. In the example, I am
> attempting to concatenate two arrays together. However it appears that
> the contents of the first array is being altered after using the concat
> function even though a copy of the array is being used. Am I doing
> something wrong here, or is this a potential bug?
> 
> Thanks
> 
> one = [[1],[2]]
> two = [['a'],['b']]
> 
> puts one.inspect
> 
> newArray =[]
> count = 0
> 
> tempArr = Array.new(one)
> 
> tempArr.each do |x|
>   x = x.concat(two.values_at(count))
>   newArray = newArray.push(x)
>   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.

-- 
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