Skip to content

Instantly share code, notes, and snippets.

@mauricioszabo
Created December 5, 2011 18:56
Show Gist options
  • Save mauricioszabo/1434772 to your computer and use it in GitHub Desktop.
Save mauricioszabo/1434772 to your computer and use it in GitHub Desktop.
ifTrue implementation on Ruby
class TrueClass
def if_true
yield
self
end
def if_false
self
end
end
class FalseClass
def if_true
self
end
def if_false
yield
self
end
end
(10 == 20).if_true {
puts "Something is wrong with the universe!"
}.if_false {
puts "Whooa, universe is alright!"
}
(10 < 20).if_true {
puts "Woo, I'm lower!"
}.if_false {
puts "Woo, I'm strange!"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment