为什么当我将常量分配给变量并更新它时,常量正被更新为?它预期的行为或错误?为什么分配给变量常量更新
ruby-1.9.3-p0 :001 > A = { :test => '123' }
=> {:test=>"123"}
ruby-1.9.3-p0 :002 > b = A
=> {:test=>"123"}
ruby-1.9.3-p0 :003 > b[:test] = '456'
=> "456"
ruby-1.9.3-p0 :004 > A
=> {:test=>"456"}
请注意,这也表明Ruby中的“常量”实际上并没有强制为常量。 – 2012-04-10 07:12:25
[Ruby中的常量赋值错误?]可能的重复(http://stackoverflow.com/questions/3010768/constant-assignment-bug-in-ruby) – 2012-04-10 07:25:52