Mega Code Archive

 
Categories / Ruby / Hash
 

What is the default value for a hash

empty = Hash.new(-1)   # Specify a default value when creating hash empty["one"]           # => -1 empty.default = -2     # Change the default value to something else empty["two"]           # => -2 empty.default          # => -2: return the default value