Skip to content

CAT 039

unurgunite edited this page Jul 11, 2026 · 3 revisions

CAT-039 — Regex.new in method → constant

Field Value
Severity warning
Confidence high
Auto-fix

Regex.new in method → constant — Creating a Regex inside a method recompiles on each call. Extract to a constant.

Bad code

def parse(str)
  regex = /pattern/
  regex.match(str)
end

Clone this wiki locally