instance method slice!

Ruby on Rails 2.3.18

Since v2.2.3 Last seen in v2.3.18

Available in: v2.2.3 v2.3.18

Signature

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

keys rest
Source
# File activesupport/lib/active_support/core_ext/hash/slice.rb, line 29
        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 29 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveSupport::CoreExtensions::Hash::Slice

Type at least 2 characters to search.

↑↓ navigate · open · esc close