爲什麼當我將常量分配給變量並更新它時,常量正被更新爲?它預期的行爲或錯誤?爲什麼分配給變量常量更新
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