Skip to content

Instantly share code, notes, and snippets.

@DavidEGrayson
Created October 20, 2011 05:55
Show Gist options
  • Save DavidEGrayson/1300520 to your computer and use it in GitHub Desktop.
Save DavidEGrayson/1300520 to your computer and use it in GitHub Desktop.
Wouldn't it be cool if we could make a BooleanWithReason Class in ruby
ugly_hair = false
ugly_nose = true.because "the nose is too small."
ugly_glasses = false
ugly_face = ugly_hair.or(ugly_nose).or(ugly_glasses)
if ugly_face.true?
puts "The face is ugly because " + ugly_face.reason # => "The face is ugly because the nose is too small."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment