Skip to content

Instantly share code, notes, and snippets.

@dedemenezes
Created October 29, 2024 19:51
Show Gist options
  • Save dedemenezes/8f47925c8d3627f63be77eda1e01f63f to your computer and use it in GitHub Desktop.
Save dedemenezes/8f47925c8d3627f63be77eda1e01f63f to your computer and use it in GitHub Desktop.
puts 'Welcome to Chritmas Gift List'
user_input = nil
gift_list = [{ name: 'Laptop', status: false }, { name: 'Flamengo Shirt', status: false }]
# indexes 0 1
while user_input != 'quit'
# 1. Give the user a new option (MARK)
puts 'Which action [list|add|delete|mark|quit]?'
user_input = gets.chomp
if user_input == 'list'
gift_list.each do |gift|
if gift[:status] == true
puts "[X] #{gift[:name]}"
else
puts "[ ] #{gift[:name]}"
end
end
elsif user_input == 'add'
puts 'Give me the gift name'
gift_to_add = gets.chomp
# each gift has a name + status
new_gift = { name: gift_to_add, status: false }
gift_list << new_gift
elsif user_input == 'delete'
puts 'Which gift do you want to remove? (give the number)'
gift_to_delete = gets.chomp
gift_list.delete(gift_to_delete)
elsif user_input == 'quit'
puts 'Goodbye ✌️'
elsif user_input == 'mark'
# Add new elsif for the mark action
# 1. Ask for which item to mark as bought (index)
puts 'Which item do you want to mark? Give me the number'
# 2. Get the index from the user
# everything that comes from the user
# will come as a String
# we need to convert to an Integer
item_number = gets.chomp.to_i
# 3. Read the right gift from the gift list by the index
item = gift_list[item_number - 1]
# 4. Change/Update the status to true
item[:status] = true
else
puts 'Wrong action. Choose between [list|add|delete|quit]'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment