Ruby

Ruby

Made by DeepSource

Prefer match? over match RB-PR1018

Performance
Major
Autofix

String#match?, Regexp#match?, and Symbol#match? are faster than match, because the methods avoid creating a MatchData object or saving backref. So, when MatchData is not used, match? can be used instead of match.

Bad practice

def foo
  if x =~ /re/
    do_something
  end
end

Recommended

def foo
  if x.match?(/re/)
    do_something
  end
end