I’ve been working with case statements in Ruby, and I was having a difficult time getting it to do what I wanted.
Things I learned:
- Case statements that take an argument after the
case(ex:case SOME_VARIABLE) can’t take logic after thewhenpart of the statement.Bad:
case thingie when thingie.match(/some regex/) # something cool happens end
Good:
case thingie when "a perfectly boring string" # something cool happens end
- Case statements that do not take an argument after the
caseCAN take logic after thewhenGood:
case when thingie.match(/some regex/) # something cool happens end
