instance method
slice!
Ruby on Rails 3.0.20
Since v3.0.20Signature
slice!(*keys)
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}
Parameters
-
keysrest
Source
# File activesupport/lib/active_support/core_ext/hash/slice.rb, line 25
def 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
Defined in activesupport/lib/active_support/core_ext/hash/slice.rb line 25
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Hash