Class | HashWithIndifferentAccess |
In: |
lib/active_support/core_ext/hash/indifferent_access.rb
|
Parent: | Hash |
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.
[]= | -> | regular_writer |
Assigns a new value to the hash:
hash = HashWithIndifferentAccess.new hash[:key] = "value"
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.
Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second. This overloaded definition prevents returning a regular hash, if reverse_merge is called on a HashWithDifferentAccess.
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!"}