Created
November 2, 2013 16:55
-
-
Save tmaeda/7281019 to your computer and use it in GitHub Desktop.
Smalltalk の #ifTrue:ifFalse:を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_if_false(true_block, flase_block) | |
true_block.call | |
end | |
end | |
class FalseClass | |
def if_true_if_false(true_block, false_block) | |
false_block.call | |
end | |
end | |
(1 < 2).if_true_if_false(->{ puts "yes"}, ->{ puts "no"}) | |
yes | |
(1 > 2).if_true_if_false(->{ puts "yes"}, ->{ puts "no"}) | |
no |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment