Actions
Bug #14008
closedAdding elements to array inside 2D array duplicates across all other arrays
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
Backport:
Description
Say I create a 2D array in Ruby using the Array.new syntax like this:
arr = Array.new 3, []
Adding elements to say, the 2nd array inside arr
produces the following result:
arr = Array.new 3, []
arr[2] << 3
arr
# => [[3], [3], [3]]
Expected behavior¶
I think this should work exactly like what happens when initializing 2D arrays using the literal syntax:
arr = [[],[],[]]
arr[2] << 3
arr
# => [[], [], [3]]
Updated by v0dro (Sameer Deshmukh) over 6 years ago
I'm so sorry I had forgotten about Array gotchas. Please close this issue.
Updated by duerst (Martin Dürst) over 6 years ago
- Status changed from Open to Rejected
Actions
Like0
Like0Like0