what is the default value for a hash : Hash values « Hash « Ruby






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

 








Related examples in the same category

1.Get an array with all the values from a hash with values:
2.Get all values as an array