aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-10-12 14:29:11 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-10-12 14:29:11 -0700
commite68b97a4b65787711e50aa1565b4dd0077a00d6d (patch)
tree229a43700512aed4a8713c09afac293622951f89 /activesupport/lib/active_support/core_ext
parent3e75369b7263a0ec09c45dd1371b1641797e9604 (diff)
parenta4b11961630febd556c962b788b11c0ed5bedb45 (diff)
downloadrails-e68b97a4b65787711e50aa1565b4dd0077a00d6d.tar.gz
rails-e68b97a4b65787711e50aa1565b4dd0077a00d6d.tar.bz2
rails-e68b97a4b65787711e50aa1565b4dd0077a00d6d.zip
Merge pull request #7007 from Mik-die/hash_extract
make Hash#extract! more symmetric with Hash#slice
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/slice.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/slice.rb b/activesupport/lib/active_support/core_ext/hash/slice.rb
index 45fec57009..de09f26f3d 100644
--- a/activesupport/lib/active_support/core_ext/hash/slice.rb
+++ b/activesupport/lib/active_support/core_ext/hash/slice.rb
@@ -32,9 +32,9 @@ class Hash
# Removes and returns the key/value pairs matching the given keys.
#
- # { a: 1, b: 2, c: 3, d: 4 }.extract!(:a, :b)
- # # => {:a => 1, :b => 2}
+ # { a: 1, b: 2, c: 3, d: 4 }.extract!(:a, :b) # => { a: 1, b: 2 }
+ # { a: 1, b: 2 }.extract!(:a, :x) # => { a: 1 }
def extract!(*keys)
- keys.each_with_object({}) { |key, result| result[key] = delete(key) }
+ keys.each_with_object(self.class.new) { |key, result| result[key] = delete(key) if has_key?(key) }
end
end