instance method
slice!
Ruby on Rails 7.2.3
Since v3.0.20Signature
slice!(*keys)
Replaces the hash with only the given keys. Returns a hash containing the removed key/value pairs.
hash = { a: 1, b: 2, c: 3, d: 4 } hash.slice!(:a, :b) # => {:c=>3, :d=>4} hash # => {:a=>1, :b=>2}
Parameters
-
keysrest
Source
# File activesupport/lib/active_support/core_ext/hash/slice.rb, line 10
def slice!(*keys)
omit = slice(*self.keys - keys)
hash = slice(*keys)
hash.default = default
hash.default_proc = default_proc if default_proc
replace(hash)
omit
end
Defined in activesupport/lib/active_support/core_ext/hash/slice.rb line 10
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Hash