Create a hash with default value : Hash Creation « Hash « Ruby
- Ruby
- Hash
- Hash Creation
Create a hash with default value
h = Hash.new("Go Fish")
h["a"] = 100
h["b"] = 200
h["a"] 100
h["c"]
# The following alters the single default object
h["c"].upcase!
h["d"]
h.keys
Related examples in the same category