在Ruby Koans中,关于_散列的部分.rb包含以下代码和注释:
def test_changing_hashes
hash = { :one => "uno", :two => "dos" }
hash[:one] = "eins"
expected = { :one => "eins", :two => "dos" }
assert_equal true, expected == hash
# Bonus Question: Why was "expected" broken out into a variable
# rather than used as a literal?
end
我想不出 comments 中 prize 问题的答案——我try 了他们建议的替代品,结果是一样的.我只知道这是为了可读性,但我看不到像本教程其他地方提到的一般编程建议.
(我知道这听起来像是某个地方已经有了答案,但我找不到任何权威.)