Skip to content

Instantly share code, notes, and snippets.

@rubysolo
Last active December 12, 2015 06:09
Show Gist options
  • Save rubysolo/4727050 to your computer and use it in GitHub Desktop.
Save rubysolo/4727050 to your computer and use it in GitHub Desktop.
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