aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/hash/slice.rb
diff options
context:
space:
mode:
authorPablo Ifran <pabloifran@gmail.com>2012-10-22 09:42:42 -0200
committerPablo Ifran <pabloifran@gmail.com>2012-10-22 09:42:42 -0200
commite041a50f2917f82950f9e5666f966d8992afd45d (patch)
tree9f4d2e3aa88f28dba9d7a1d24d46977e0642a1eb /activesupport/lib/active_support/core_ext/hash/slice.rb
parent3e6b2f5d38e0f31db3fb0fcd3bbab92666a0e3e2 (diff)
parentae27acb342c575ce19d5ad78cb13ba23f826fab1 (diff)
downloadrails-e041a50f2917f82950f9e5666f966d8992afd45d.tar.gz
rails-e041a50f2917f82950f9e5666f966d8992afd45d.tar.bz2
rails-e041a50f2917f82950f9e5666f966d8992afd45d.zip
Merge branch 'master' of https://github.com/lifo/docrails
Conflicts: activerecord/lib/active_record/callbacks.rb
Diffstat (limited to 'activesupport/lib/active_support/core_ext/hash/slice.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/slice.rb8
1 files changed, 4 insertions, 4 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..a92c5968ed 100644
--- a/activesupport/lib/active_support/core_ext/hash/slice.rb
+++ b/activesupport/lib/active_support/core_ext/hash/slice.rb
@@ -21,7 +21,7 @@ class Hash
# Returns a hash containing the removed key/value pairs.
#
# { a: 1, b: 2, c: 3, d: 4 }.slice!(:a, :b)
- # # => {:c => 3, :d => 4}
+ # # => {c: 3, d: 4}
def slice!(*keys)
keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
omit = slice(*self.keys - keys)
@@ -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