aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2008-12-26 21:56:21 +0000
committerPratik Naik <pratiknaik@gmail.com>2008-12-26 21:56:21 +0000
commitf4f8923cf0ef5bd31f9e98cecf4603d0c4bde296 (patch)
tree2c5d9b59cefa59476ef48ea85aa0c2f00e1e33c1 /activesupport/lib
parent6dc12881110d26bb952bd0f565623144f10a07b6 (diff)
parent5cebe69e74d411c3c9e5f6ab9d4b2b16ee36177c (diff)
downloadrails-f4f8923cf0ef5bd31f9e98cecf4603d0c4bde296.tar.gz
rails-f4f8923cf0ef5bd31f9e98cecf4603d0c4bde296.tar.bz2
rails-f4f8923cf0ef5bd31f9e98cecf4603d0c4bde296.zip
Merge commit 'fred/pullable'
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/slice.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/slice.rb b/activesupport/lib/active_support/core_ext/hash/slice.rb
index 88df49a69f..d845a6d8ca 100644
--- a/activesupport/lib/active_support/core_ext/hash/slice.rb
+++ b/activesupport/lib/active_support/core_ext/hash/slice.rb
@@ -24,10 +24,17 @@ module ActiveSupport #:nodoc:
end
# Replaces the hash with only the given keys.
+ # Returns a hash contained the removed key/value pairs
+ # {:a => 1, :b => 2, :c => 3, :d => 4}.slice!(:a, :b) # => {:c => 3, :d =>4}
def slice!(*keys)
- replace(slice(*keys))
+ keys = keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
+ omit = slice(*self.keys - keys)
+ hash = slice(*keys)
+ replace(hash)
+ omit
end
end
end
end
end
+