Project

General

Profile

Actions

Bug #12765

closed

An [element] multiply an number, every element in the list would be modified after modifying only one of then.

Bug #12765: An [element] multiply an number, every element in the list would be modified after modifying only one of then.

Added by fanjieqi (jieqi fan) about 10 years ago. Updated about 10 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
[ruby-core:77286]

Description

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.

Actions

Also available in: PDF Atom