class RuboCop::Cop::Performance::RedundantMatch

return regex.match(‘str’)
method(str.match(/regex/))
@good
end
do_something
while regex.match(‘str’)
do_something if str.match(/regex/)
@bad
@example
where the integral return value of ‘=~` would do just as well.
This cop identifies use of `Regexp#match` or `String#match` in a context

def autocorrect(node)

def autocorrect(node)
  # Regexp#match can take a second argument, but this cop doesn't
  # register an offense in that case
  return unless node.first_argument.regexp_type?
  new_source =
    node.receiver.source + ' =~ ' + node.first_argument.source
  ->(corrector) { corrector.replace(node.source_range, new_source) }
end

def on_send(node)

def on_send(node)
  return unless match_call?(node) &&
                (!node.value_used? || only_truthiness_matters?(node)) &&
                !(node.parent && node.parent.block_type?)
  add_offense(node, :expression)
end