Last active
December 12, 2015 06:09
-
-
Save rubysolo/4727050 to your computer and use it in GitHub Desktop.
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
def accept_and_run_command | |
loop do | |
print "enter command> " | |
input = gets.chomp.split(/\s+/) | |
case input.first | |
when "foo" then puts "got command 'foo'" | |
when "bar" then puts "got command 'bar'" | |
else | |
puts "Sorry, but I don't know how to '#{ input.first }'!" | |
redo # <-- the redo keyword goes back to the start of the enclosing loop/iterator | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment