Skip to content

Instantly share code, notes, and snippets.

@tivtag
Created May 9, 2011 19:43
Show Gist options
  • Save tivtag/963232 to your computer and use it in GitHub Desktop.
Save tivtag/963232 to your computer and use it in GitHub Desktop.
Ruby method that takes [Symbol -> Function]
# 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