class RuboCop::Cop::Style::HashSlice


{foo: 1, bar: 2, baz: 3}.slice(:bar)
# good
{foo: 1, bar: 2, baz: 3}.reject {|k, v| !k.in?(%i) }
{foo: 1, bar: 2, baz: 3}.select {|k, v| k.in?(%i) }
# bad
{foo: 1, bar: 2, baz: 3}.reject {|k, v| %i.exclude?(k) }
{foo: 1, bar: 2, baz: 3}.select {|k, v| !%i.exclude?(k) }
# bad
@example AllCops:ActiveSupportExtensionsEnabled: true
{foo: 1, bar: 2, baz: 3}.reject {|k, v| !k.in?(%i) }
{foo: 1, bar: 2, baz: 3}.select {|k, v| k.in?(%i) }
# good
{foo: 1, bar: 2, baz: 3}.reject {|k, v| %i.exclude?(k) }
{foo: 1, bar: 2, baz: 3}.select {|k, v| !%i.exclude?(k) }
# good
@example AllCops:ActiveSupportExtensionsEnabled: false (default)
{foo: 1, bar: 2, baz: 3}.slice(:bar)
# good
{foo: 1, bar: 2, baz: 3}.filter {|k, v| %i.include?(k) }
{foo: 1, bar: 2, baz: 3}.reject {|k, v| !%i.include?(k) }
{foo: 1, bar: 2, baz: 3}.select {|k, v| %i.include?(k) }
# bad
{foo: 1, bar: 2, baz: 3}.select {|k, v| k.eql?(:bar) }
{foo: 1, bar: 2, baz: 3}.filter {|k, v| k == :bar }
{foo: 1, bar: 2, baz: 3}.reject {|k, v| k != :bar }
{foo: 1, bar: 2, baz: 3}.select {|k, v| k == :bar }
# bad
@example
is a ‘Hash` or responds to the replacement method.
This cop is unsafe because it cannot be guaranteed that the receiver
@safety
modify the receiver.
This cop doesn’t check for ‘Hash#delete_if` and `Hash#keep_if` because they
when using `==` or `!=`.
For safe detection, it is limited to commonly used string and symbol comparisons
(`Hash#slice` was added in Ruby 2.5.)
This cop should only be enabled on Ruby version 2.5 or higher.
that can be replaced with `Hash#slice` method.
Checks for usages of `Hash#reject`, `Hash#select`, and `Hash#filter` methods

def preferred_method_name

def preferred_method_name
  'slice'
end

def semantically_subset_method?(node)

def semantically_subset_method?(node)
  semantically_slice_method?(node)
end