Skip to content
Browse files

Fix OrderedHash merging with block given.

  • Loading branch information...
1 parent 1aae5e7 commit b2d4142fb754730fb4ccae17c942b66a64cbfed2 @Antiarchitect Antiarchitect committed Jun 16, 2011
Showing with 7 additions and 3 deletions.
  1. +7 −3 activesupport/lib/active_support/ordered_hash.rb
View
10 activesupport/lib/active_support/ordered_hash.rb
@@ -130,14 +130,18 @@ def shift
end
def merge!(other_hash)
- other_hash.each {|k,v| self[k] = v }
+ if block_given?
+ other_hash.each { |k, v| self[k] = key?(k) ? yield(k, self[k], v) : v }
+ else
+ other_hash.each { |k, v| self[k] = v }
+ end
self
end
alias_method :update, :merge!
- def merge(other_hash)
- dup.merge!(other_hash)
+ def merge(other_hash, &block)
+ dup.merge!(other_hash, &block)
end
# 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.