When modifying an element in a row, the result becomes corrupted when I
try to read it back.  new_row is being modified correctly.  It is then
being appended to new_rows (plural).  But when I read new_rows back,
each element contains only the last new_row created.  What gives?

$ cat test.rb;./test.rb
#!/usr/bin/env ruby

def test1
  row = [ 'field1' , 'field2', 'field3' ]
  test = [ 'test1', 'test2', 'test3' ]
  new_rows = Array.new
  new_row = row
  test.each { |value|
    new_row[2] = value
    puts "new_row: #{new_row}"
    new_rows << new_row
  }
  puts
  for ixt in 0..new_rows.size - 1
    puts "new_rows[#{ixt}]: #{new_rows[ixt]}"
  end
end
test1

new_row: field1field2test1
new_row: field1field2test2
new_row: field1field2test3

new_rows[0]: field1field2test3
new_rows[1]: field1field2test3
new_rows[2]: field1field2test3

-- 
Posted via http://www.ruby-forum.com/.