From: ruby-core@... Date: 2016-09-15T19:20:08+00:00 Subject: [ruby-core:77289] [Ruby trunk Bug#12765][Rejected] An [element] multiply an number, every element in the list would be modified after modifying only one of then. Issue #12765 has been updated by Marc-Andre Lafortune. Status changed from Open to Rejected Clearly not a bug. list[0][0] = -1 # => same as doing: element[0] = -1 For further questions, please use general ruby mailing list or StackOverflow, thanks. ---------------------------------------- Bug #12765: An [element] multiply an number, every element in the list would be modified after modifying only one of then. https://bugs.ruby-lang.org/issues/12765#change-60522 * Author: jieqi fan * Status: Rejected * Priority: Normal * Assignee: * ruby -v: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14] * Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN ---------------------------------------- ` element = [1] list = [element.clone] * 3 p list #[[1], [1], [1]] list[0][0] = -1 # should be [[-1], [1], [1]] p list # [[-1], [-1], [-1]] ` The list initialized as [ [1], [1] ]. Then we assign the list[0][0], which is 1, as -1, and the list[1][0] is changed as -1 too. -- https://bugs.ruby-lang.org/ Unsubscribe: