Created
April 10, 2010 08:28
-
-
Save frogstarr78/361911 to your computer and use it in GitHub Desktop.
Ruby Methods emulating Smalltalk Conditionals
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
module MethodsLikeSmalltalkConditionals | |
module Kernel | |
def is_true | |
Proc.new { yield } | |
end | |
def is_false | |
Proc.new { yield } | |
end | |
end | |
class ::Object | |
def nil? is_true, is_false | |
is_false.call | |
self | |
end | |
end | |
class ::NilClass | |
def nil? is_true, is_false | |
is_true.call | |
self | |
end | |
end | |
include Kernel | |
def run_example bob | |
bob.nil? is_true { puts 'nil' }, is_false { puts 'notnil' } | |
yield bob if block_given? | |
end | |
end | |
include MethodsLikeSmalltalkConditionals | |
run_example nil do |who| | |
who = false | |
who.nil? is_true { puts 'true' }, is_false { puts 'false' } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment