How can I return the program back to the CRUD menu if the user wants to
take another action? I thought about using returns, but I’m not quite
sure how that would work.
#movie hash
movies = { superbad: 4,
miami_vice: 0,
juno: 0
}
#Get CRUD input
puts “Do you want to add, update, display, delete or exit?”
choice = gets.chomp.downcase
#case since there are many conditions/options
case choice
when ‘add’
puts “Give me a movie title”
title = gets.chomp
if movies[title.to_sym].nil?
puts “Now rate it”
rating = gets.chomp
movies[title.to_sym] = rating.to_i
else
puts “That movie already exists”
end
when “update”
puts “Give me the title.”
title = gets.chomp
if movies[title.to_sym].nil?
puts “That movie does not exist”
else
puts “What is the new rating?”
rating = gets.chomp
movies[title.to_sym] = rating.to_i
puts “#{rating} is the new rating!”
end
when “display”
movies.each { |x , y| puts “#{x}: #{y}”}
when “delete”
puts “What is the title you want to remove?!”
title = gets.chomp
if movies[title.to_sym].nil?
puts “Error, movie is not listed.”
else
movies.delete(title.to_sym)
puts “#{title} has been removed”
end
when ‘exit’
return 0
else
puts “Error!”
end
#how to make it loop back to beginning?