Skip to content

Instantly share code, notes, and snippets.

@frogstarr78
Created April 10, 2010 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frogstarr78/361911 to your computer and use it in GitHub Desktop.
Save frogstarr78/361911 to your computer and use it in GitHub Desktop.
Ruby Methods emulating Smalltalk Conditionals
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