Sto passando about_hashes.rb da RubyKoans. 1 esercizio mi ha perplesso:Valori hash predefiniti in Ruby (Rubykoans.com -> about_hashes.rb)
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
La mia ipotesi è che Hash.new ("DOS") rende "dos" La risposta di default per tutti i tasti inesistenti. Ho ragione?
Ho modificato la mia domanda, dovrebbe essere "dos" invece di nil. –