在接下来的内容中,
以下内容中,
input_1
发生了变化:def method_1(a)
a << "new value"
end
input_1 = []
method_1(input_1)
input_1 #=> ["new value"]
以下内容中,
input_2
不会发生改变:def method_2(a)
a = ["new value"]
end
input_2 = []
method_2(input_2)
input_2 #=> []
为什么input_1
会改变而input_2
不会改变?
['new value']
吗? - Alexander Presbermethod_2
仅仅是用与另一个变量相同的名称赋值了一个新变量。 - max pleaner