I came across this problem and I need some help understanding why the original object was also changed; I was under the impression that ".dup" will create a new object for the pointer to reference, is this wrong?
class Pawn
attr_accessor :position
def initialize(position)
@position = position
end
end
pawn = Pawn.new([0, 1])
pawn_copy = pawn.dup
pawn_copy.position[1] = "CHANGED"
pawn.position #=> the result is [0, "CHANGED"]