我是一个Ruby新手
我知道Ruby在函数参数传递时采用的是引用传递
但是,我感觉这与常规的C/C++风格的引用传递略有不同
示例代码:
def test1(str)
str += ' World!'
end
def test2(str)
str << ' World!'
end
str = 'Hello'
test1(str)
p str # Hello
test2(str)
p str # Hello World!
如果我在使用C/C++中的引用,我期望
test1
也能返回Hello World!
。这只是出于好奇,任何解释都会被赞赏。