MΓ³dulo 26 Β· Enumerable, Enumerator & Pattern Matching β LecciΓ³n 6 de 6 Β· ~9 min
Regexp That Earns Its Keep (Capstone)
Match, don't extract, when you only need a yes/no
Regular expressions in Ruby are objects (/.../ is a Regexp literal). The first senior habit: use the right method for the job. To test whether something matches, use match? β it returns a plain boolean and skips the expensive capture-group machinery and the $~ globals. Reserve match/=~ for when you actually need the captured pieces.
In an interview, say: "I use
match?for boolean checks β it's faster and has no side effects on the$~globals. I only reach formatchor named captures when I need to extract data, not just confirm a match."