Forked from frogstarr78/HashLikeSmallTalkConditionals.rb
Created
August 30, 2011 18:44
-
-
Save fogus/1181677 to your computer and use it in GitHub Desktop.
Ruby Hashes emulating Smalltalk Conditionals rr
This file contains hidden or 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