Skip to content
This repository
Browse code

Fix OrderedHash merging with block given.

  • Loading branch information...
commit b2d4142fb754730fb4ccae17c942b66a64cbfed2 1 parent 1aae5e7
Andrey Voronkov Antiarchitect authored

Showing 1 changed file with 7 additions and 3 deletions. Show diff stats Hide diff stats

  1. +7 3 activesupport/lib/active_support/ordered_hash.rb
10 activesupport/lib/active_support/ordered_hash.rb
@@ -130,14 +130,18 @@ def shift
130 130 end
131 131
132 132 def merge!(other_hash)
133   - other_hash.each {|k,v| self[k] = v }
  133 + if block_given?
  134 + other_hash.each { |k, v| self[k] = key?(k) ? yield(k, self[k], v) : v }
  135 + else
  136 + other_hash.each { |k, v| self[k] = v }
  137 + end
134 138 self
135 139 end
136 140
137 141 alias_method :update, :merge!
138 142
139   - def merge(other_hash)
140   - dup.merge!(other_hash)
  143 + def merge(other_hash, &block)
  144 + dup.merge!(other_hash, &block)
141 145 end
142 146
143 147 # When replacing with another hash, the initial order of our keys must come from the other hash -ordered or not.

0 comments on commit b2d4142

Please sign in to comment.
Something went wrong with that request. Please try again.