Skip to content

Commit

Permalink
Small amendments for Hash#merge with IndifferentAccess
Browse files Browse the repository at this point in the history
1. Use `indifferent_writer` in `convert!` so that when
`indifferent_writer`, `convert_key` or `indifferent_value` is
overridden in included class, `merge` can use those.

2. `convert!` was calling twice if `other` hash was lacking
indifference. `IndifferentAccess.inject!` already does conversion.
  • Loading branch information
yogeshjain999 committed Jun 6, 2020
1 parent c066135 commit b025025
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/hashie/extensions/indifferent_access.rb
Expand Up @@ -74,7 +74,7 @@ def convert_key(key)
# is injecting itself into member hashes.
def convert!
keys.each do |k| # rubocop:disable Performance/HashEachMethods
regular_writer convert_key(k), indifferent_value(regular_delete(k))
indifferent_writer k, regular_delete(k)
end
self
end
Expand Down Expand Up @@ -133,7 +133,7 @@ def indifferent_replace(other_hash)

def merge(*args)
result = super
IndifferentAccess.inject!(result) if hash_lacking_indifference?(result)
return IndifferentAccess.inject!(result) if hash_lacking_indifference?(result)
result.convert!
end

Expand Down

0 comments on commit b025025

Please sign in to comment.