Skip to content

Instantly share code, notes, and snippets.

@frogstarr78
Created April 10, 2010 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save frogstarr78/361910 to your computer and use it in GitHub Desktop.
Save frogstarr78/361910 to your computer and use it in GitHub Desktop.
Ruby Hashes emulating Smalltalk Conditionals
#!/usr/bin/env ruby
module HashLikeSmalltalkConditionals
class ::Object
def nil? hash
hash[:if_false].call
self
end
end
class ::NilClass
def nil? hash
hash[:if_true].call
self
end
end
def run_example bob
bob.nil? :if_true => proc { puts 'true' }, :if_false => proc { puts 'false' }
yield bob if block_given?
end
end
include HashLikeSmalltalkConditionals
run_example nil
run_example false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment