From: Florian Gross Date: 2004-09-29T03:49:20+09:00 Subject: Re: weird behavior pushing an array onto an array Brian Candler wrote: >>>In my program, I fill an array, a, with data and push it onto an array b >>>which is initially empty. >>You push the same array over and over. You want to push a copy instead. >>Use #clone or #dup to get a copy of the Array. > Beware that may not be enough by itself, because the array contains strings; > even if you dup the array you will still have references to the same > strings. This will become apparent if you later modify one of the strings: Thank you for the correction, you are right of course. > Or more compactly, > > b = (1..5).collect { ["ACINX", "28.53", "15.63", "3.95", "7.76", "1.05", 0] } Or even this: b = Array.new(5) { ["ACINX", "28.53", "15.63", "3.95", "7.76", "1.05", 0] } > Regards, > Brian. More regards, Florian Gross