From 58e21a4a0d4eefc395139e88c1f184b9eaf0b4c4 Mon Sep 17 00:00:00 2001 From: Paul Mucur Date: Fri, 11 Jun 2010 23:38:18 +0100 Subject: Support passing a block to ActiveSupport::OrderedHash's merge and merge! [#4838 state:committed] For better consistency with Ruby's own Hash implementation. Signed-off-by: Xavier Noria --- activesupport/lib/active_support/ordered_hash.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/active_support/ordered_hash.rb') diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index e1a2866863..eda33f827e 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -130,12 +130,16 @@ module ActiveSupport end def merge!(other_hash) - other_hash.each {|k,v| self[k] = v } + if block_given? + other_hash.each {|k,v| self[k] = yield(k, self[k], v) } + else + other_hash.each {|k,v| self[k] = v } + end self end - 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. -- cgit v1.2.3