Created
December 5, 2011 18:56
-
-
Save mauricioszabo/1434772 to your computer and use it in GitHub Desktop.
ifTrue implementation on Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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