From: sameer.deshmukh93@... Date: 2017-10-12T13:44:31+00:00 Subject: [ruby-core:83238] [Ruby trunk Bug#14008] Adding elements to array inside 2D array duplicates across all other arrays Issue #14008 has been updated by v0dro (Sameer Deshmukh). I'm so sorry I had forgotten about Array gotchas. Please close this issue. ---------------------------------------- Bug #14008: Adding elements to array inside 2D array duplicates across all other arrays https://bugs.ruby-lang.org/issues/14008#change-67190 * Author: v0dro (Sameer Deshmukh) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux] * Backport: 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- 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: ~~~ ruby 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: ~~~ ruby arr = [[],[],[]] arr[2] << 3 arr # => [[], [], [3]] ~~~~ -- https://bugs.ruby-lang.org/ Unsubscribe: