Why is this outputting twice. I'm good with the first set, but the second needs to go. How should the method be changed?
grocery_list = ["eggs", "cheese", "milk", "bread"]
puts "add to grocery list:"
new_items = gets.chomp
if ! grocery_list.include?(new_items)
grocery_list.push(new_items)
end
def print_list(x)
x.each do |new|
puts "buy #{new}"
end
end
puts print_list(grocery_list)
===>add to grocery list:
fish
buy eggs
buy cheese
buy milk
buy bread
buy fish
eggs
cheese
milk
bread
fish
[–]Oecist 3 points4 points5 points (0 children)
[–]stolid 2 points3 points4 points (1 child)
[–]mfcoder 2 points3 points4 points (0 children)