Hash¶
Instance Methods¶
Hash#==¶
If the RHS argument is a non-hash and it responds to the to_hash method, that will be used for the comparison.
Hash#[]¶
Redefined to allow you to select multiple keys simultaneously (i.e. hash slicing), returning an array of values.
hash = {'a' => 1, 'b' =>2, 'c' => 3}
hash['a', 'b'] => [1, 2]
Note that there is one subtle difference between Hash#[] and Hash#values_at. The former only returns a single value if a single key is provided, while the latter returns an array regardless of the number of keys provided.
hash.values_at('a') => [1]
hash['a'] => 1
Hash#[]=¶
Redefined to handle slice assignment.
hash = {'a' => 1, 'b' =>2, 'c' => 3}
# One to one
hash['a', 'b'] = 'hello', 'world'
hash['a'] => 'hello'
hash['b'] => 'world'
# One to many
hash['a', 'b] = 7
hash['a', 'b'] => [7, nil]
# Many to one
hash['a'] = 'hello', 'world'
hash['a'] => ['hello', 'world']
Hash#store¶
Removed. No one used this alias for Hash#[]= in practice.