努力寻找有关为什么会这样工作的文档:
1 def test_default_value_is_the_same_object
2 hash = Hash.new([])
3
4 hash[:one] << "uno"
5 hash[:two] << "dos"
6
7 assert_equal ["uno", "dos"], hash[:one]
8 assert_equal ["uno", "dos"], hash[:two]
9 assert_equal ["uno", "dos"], hash[:three]
10
11 assert_equal true, hash[:one].object_id == hash[:two].object_id
12 end
我原以为“uno”会分配给 hash[:one] 键,而 hash[:two] 会收到“dos”。我已经对其进行了更正,使其通过了测试,但是我不知道为什么它会以这种方式运行。有人可以指出我缺少什么或指导我查看有关此特定方面的相关文档。谢谢。