Skip to content

Instantly share code, notes, and snippets.

@iancanderson
Created November 3, 2011 23:03
Show Gist options
  • Save iancanderson/1338203 to your computer and use it in GitHub Desktop.
Save iancanderson/1338203 to your computer and use it in GitHub Desktop.
looping_prompt.rb
# 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