A hint as to the reason is in the name of the tests.
test_default_value_is_the_same_object
is there to show you that when you ask for hash[:some_value_that_doesnt_exist_yet]
, by default, you get back the default value you specified -- which is the same object every time. By modifying that object, you modify it for every nonexistent key. Modifying hash[:one]
also modifies hash[:two]
.
test_default_value_with_block
shows the construction of a Hash using a block, which will be used to provide a new value for each key. When you do it like that, the values for hash[:one]
and hash[:two]
are distinct.