This class has dubious semantics and we only have it so that people can write params[:key] instead of params[‘key’] and they get the same value for both keys.
Assigns a new value to the hash:
hash = HashWithIndifferentAccess.new hash[:key] = "value"
Removes a specified key from the hash.
Returns an exact copy of the hash.
Fetches the value for the specified key, same as doing hash[key]
Checks the hash for a key matching the argument passed in:
hash = HashWithIndifferentAccess.new hash["key"] = "value" hash.key? :key # => true hash.key? "key" # => true
Merges the instantized and the specified hashes together, giving precedence to the values from the second hash Does not overwrite the existing hash.
Convert to a Hash with String keys.
Updates the instantized hash with values from the second:
hash_1 = HashWithIndifferentAccess.new hash_1[:key] = "value" hash_2 = HashWithIndifferentAccess.new hash_2[:key] = "New Value!" hash_1.update(hash_2) # => {"key"=>"New Value!"}
Returns an array of the values at the specified indices:
hash = HashWithIndifferentAccess.new hash[:a] = "x" hash[:b] = "y" hash.values_at("a", "b") # => ["x", "y"]