也许我今天盯着屏幕太久了,但我认为应该非常基本的东西让我很难过。
我正在尝试制作一个变量的“副本”,这样我就可以在不修改原始变量的情况下对其进行操作。
# original var is set
foo = ["a","b","c"]
# i want a copy of the original var so i dont modify the original
bar = foo
# modify the copied var
bar.delete("b")
# output the values
puts bar # outputs: ["a","c"] - this is right
puts foo # outputs: ["a","c"] - why is this also getting modified?
我不想foo
被改变。