I'm going through about_hashes.rb from RubyKoans. 1 exercise got me puzzled:
def test_default_value
hash1 = Hash.new
hash1[:one] = 1
assert_equal 1, hash1[:one] #ok
assert_equal nil, hash1[:two] #ok
hash2 = Hash.new("dos")
hash2[:one] = 1
assert_equal 1, hash2[:one] #ok
assert_equal "dos", hash2[:two] #hm?
end
My guess is that Hash.new("dos") makes "dos" the default answer for all non-existent keys. Am I right?