Created
November 3, 2011 23:03
-
-
Save iancanderson/1338203 to your computer and use it in GitHub Desktop.
looping_prompt.rb
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
# User story: | |
# - user runs ruby tasky.rb | |
# 1.) print menu | |
# tasky: "what would you like to do?" | |
# (n)ew task | |
# (l)ist tasks | |
# (c)omplete task | |
# (q)uit | |
# 2.) getting input | |
# user types in 'l', hits enter | |
# 3.) acting accordingly | |
# tasky shows their task list | |
# (re-prompt user, show menu) | |
# | |
def print_menu | |
puts "what would you like to do?" | |
puts "(n)ew" | |
puts "(c)omplete" | |
puts "(q)uit" | |
end | |
def get_input | |
gets.chomp | |
end | |
def act(input) | |
if input == "q" | |
puts "quitting..." | |
return false | |
else | |
puts "you typed #{input}" | |
return true | |
end | |
end | |
while(true) | |
print_menu | |
break unless act(get_input) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment