aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorMikhail Dieterle <MikDiet@gmail.com>2012-07-09 00:10:16 +0300
committerMikhail Dieterle <MikDiet@gmail.com>2012-10-08 01:20:36 +0300
commit5d27338ab08496b41ef71c789e5ae4de0b3b8df7 (patch)
tree3fba86faec8e3836d0bee8f84ad14376a4d167af /activesupport/lib/active_support
parent800604e4452dcc39849cbab087d96c3b7ca44e47 (diff)
downloadrails-5d27338ab08496b41ef71c789e5ae4de0b3b8df7.tar.gz
rails-5d27338ab08496b41ef71c789e5ae4de0b3b8df7.tar.bz2
rails-5d27338ab08496b41ef71c789e5ae4de0b3b8df7.zip
make Hash#extract! more symmetric with Hash#slice
Diffstat (limited to 'activesupport/lib/active_support')
-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