Skip to content

Instantly share code, notes, and snippets.

@tmaeda
Created November 2, 2013 16:55
Show Gist options
  • Save tmaeda/7281019 to your computer and use it in GitHub Desktop.
Save tmaeda/7281019 to your computer and use it in GitHub Desktop.
Smalltalk の #ifTrue:ifFalse:をRubyで。
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