From: "nobu (Nobuyoshi Nakada)" Date: 2012-06-13T05:13:19+09:00 Subject: [ruby-core:45601] [ruby-trunk - Bug #6580][Rejected] Assigning a value to a single element in an array that is contained in an array of arrays, updates the element in that position in all of the contained arrays Issue #6580 has been updated by nobu (Nobuyoshi Nakada). Status changed from Open to Rejected ---------------------------------------- Bug #6580: Assigning a value to a single element in an array that is contained in an array of arrays, updates the element in that position in all of the contained arrays https://bugs.ruby-lang.org/issues/6580#change-27199 Author: jmoline (James Moline) Status: Rejected Priority: Normal Assignee: Category: Target version: ruby -v: ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0] =begin Came across this bug the other day in both 1.8 and 1.9.3. It seems like it would have been discovered before, but I can't find anywhere that it has been reported. Basically, when you have an array of arrays, and you attempt to assign a value to a single element of one of those arrays, it assigns the value to that element in all of the arrays. Example: (({arr = Array.new(5, Array.new(5))})) [ [nil, nil, nil, nil, nil], [nil, nil, nil, nil, nil], [nil, nil, nil, nil, nil], [nil, nil, nil, nil, nil], [nil, nil, nil, nil, nil] ] (({arr[0][0] = 3})) [ [3, nil, nil, nil, nil], [3, nil, nil, nil, nil], [3, nil, nil, nil, nil], [3, nil, nil, nil, nil], [3, nil, nil, nil, nil], ] (({arr[2][3] = "test"})) [ [3, nil, nil, "test", nil], [3, nil, nil, "test", nil], [3, nil, nil, "test", nil], [3, nil, nil, "test", nil], [3, nil, nil, "test", nil], ] =end -- http://bugs.ruby-lang.org/