Jan 28, 2009

Win/Fail in Ruby

Very simple yet quite amusing:
def win
true
end

FAIL = nil
Put this somewhere in your Ruby code, and you'll be able to write:
if something == win
...
if something == FAIL
Originally I had it with a lowercase fail, but that might conflict with some library somewhere. Plus it is cooler if it is in all caps.

This was inspired by a tweet from Giles Bowkett.

No comments: