Ruby - local variable gets modified when changing instance variable
问题 temp gets @board.dup , and @board array is modified. However, temp gets modified as well! I have tried reading all the related documentations but still couldn't figure out an explanation. class Test def initialize @board = [[1,2],[3,4], [5,6]] end def modify temp = @board.dup #Also tried .clone print 'temp: ';p temp print '@board: ';p @board @board.each do |x| x << "x" end print "\ntemp: ";p temp print '@board: ';p @board end end x = Test.new x.modify Output: temp: [[1, 2], [3, 4], [5, 6]]