What's your array an array of? Array.dup will copy the array to a new  
array, but if the values in the array are references to some class  
you're using, it'll be a different array of the same items.  
Primitives would be copied correctly. You need to do your own deep  
copy if it's a more complicated array value.

-Bryan

On Dec 24, 2007, at 7:19 AM, jbieger / gmail.com wrote:

> Hi, I'm a total newbie with Ruby and I was trying to make this
> function that would get a (multidimensional) array, make a copy, make
> some changes to the copy and then return the copy, without altering
> the original array. However, no matter what I try, the original array
> gets altered. Here is my code:
>
> def prune_times (times)
> #	copy = times
> #	copy = Array.new(times)
> #	copy = times.clone
> 	copy = times.dup
> 	copy.each do |map|
> 		map.each do |task|
> 			task.replace(best_n(task, 2))
> 		end
> 	end
> 	return copy
> end
>
> Any help would be greatly appreciated!
>
> Jordi
>