Saturday, December 19, 2015

Important semantic effects of small syntax errors : Ruby regex

Here's a recent typo that had interestingly important effects:

Meant to write

 if line =~ /some-reg-expression/

Actually wrote:

 if line = ~/some-reg-expression/

Result: found nothing!

FYI, the type of ~/some-reg-expression/ is NilClass