Mega Code Archive

 
Categories / Ruby / Hash
 

Default= Sets the default value

h = { "a" => 100, "b" => 200 } h.default = "Go fish" h["a"]   h["z"]   # This doesn't do what you might hope... h.default = proc do |hash, key|     hash[key] = key + key end puts h[2]  puts h["cat"]