Created
April 10, 2010 08:24
-
-
Save frogstarr78/361910 to your computer and use it in GitHub Desktop.
Ruby Hashes 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
#!/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