class ActiveSupport::HashWithIndifferentAccess
def update(other_hash)
hash_2['key'] = 12
hash_1[:key] = 10
keys follow the semantics of indifferent access:
in the receiver, and the value in +other_hash+. The rules for duplicated
by the result of invoking the block with the duplicated key, the value
When given a block, the value for duplicated keys will be determined
of the values end up in the receiver, but which one is unspecified.
If the argument is a regular hash with keys +:key+ and +"key"+ only one
In either case the merge respects the semantics of indifferent access.
ActiveSupport::HashWithIndifferentAccess or a regular +Hash+.
The argument can be either an
hash_1.update(hash_2) # => {"key"=>"New Value!"}
hash_2[:key] = 'New Value!'
hash_2 = ActiveSupport::HashWithIndifferentAccess.new
hash_1[:key] = 'value'
hash_1 = ActiveSupport::HashWithIndifferentAccess.new
Updates the receiver in-place, merging in the hash passed as argument:
def update(other_hash) if other_hash.is_a? HashWithIndifferentAccess super(other_hash) else other_hash.to_hash.each_pair do |key, value| if block_given? && key?(key) value = yield(convert_key(key), self[key], value) end regular_writer(convert_key(key), convert_value(value)) end self end end