diff options
author | trans <transfire@gmail.com> | 2008-12-25 00:24:05 +0000 |
---|---|---|
committer | Frederick Cheung <frederick.cheung@gmail.com> | 2008-12-26 18:25:42 +0000 |
commit | c9d4335418823500548ad8fbc86af7c910b7644b (patch) | |
tree | d28fac55b165cfd3aaa8a9a0f38ea3235fb54485 /activesupport/lib/active_support | |
parent | dce0da77e7ef602f7420f43c0d1aba5a99a00bdb (diff) | |
download | rails-c9d4335418823500548ad8fbc86af7c910b7644b.tar.gz rails-c9d4335418823500548ad8fbc86af7c910b7644b.tar.bz2 rails-c9d4335418823500548ad8fbc86af7c910b7644b.zip |
MaKe Hash#slice! return removed values, akin to Array [#971 state:resolved]
Signed-off-by: Frederick Cheung <frederick.cheung@gmail.com>
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/slice.rb | 9 |
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 + |