最近遇到一个很疑惑的问题。直接上 code 吧
array1 = []
array2 = []
a =[1,2,3,4]
b =[1,2,3,4]
3.times do
a.rotate!
array1 << a
end
p array1
3.times do
b = b.rotate
array2 << b
end
p array2
结果是
[[4, 1, 2, 3], [4, 1, 2, 3], [4, 1, 2, 3]]
[[2, 3, 4, 1], [3, 4, 1, 2], [4, 1, 2, 3]]
想请教下为什么第一个的 rotate!不管用呢?