Created
May 9, 2011 19:43
-
-
Save tivtag/963232 to your computer and use it in GitHub Desktop.
Ruby method that takes [Symbol -> Function]
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
# Ruby 1.9.2 | |
# Attempt at creating a method that takes a string and mappings of symbols to functions. | |
# | |
# Is there a better way that does not require as many {} and ->s? | |
choice 'A monster appears behind you! Start [run]ning away or [jump] from the cliff?', | |
run:-> { | |
puts "You just got eaten. Sorry." | |
}, | |
jump:-> { | |
puts "You fall to your death!" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment