Wonder of the When-Be-Splat
Well, okay, yes, we already know Ruby is expressive. And, if I know you, you’ll see a drop of awesomeness in:
BOARD_MEMBERS = ['Jan', 'Julie', 'Archie', 'Stewick'] HISTORIANS = ['Braith', 'Dewey', 'Eduardo'] case name when *BOARD_MEMBERS "You're on the board! A congratulations is in order." when *HISTORIANS "You are busy chronicling every deft play." end
I was refactoring a parser and it occured to me that I could just do a
when *tokens.keys at one point. Ruby treats it just like a list of conditions. Consider Olympic ice dancing out-graced!
Addendum: I’m just gonna log a few of the other discoveries implied here, just to prove how handily this waxes
if..include?’s sorry snout.
case name when "Arthur", *BOARD_MEMBERS "Either you are a board member... or you are Arthur." end case name when *BOARD_MEMBERS|HISTORIANS "We welcome you all to the First International Symposium of Board Members and Historians Alike." end