This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: Wonder of the When-Be-Splat
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
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!