Newbie. Help with iterators

So, I just started studying ruby and Im learning about iterators. I came
across an exercise where they show you how to make a grocery list with
the users input.

but I don’t seem to get the code right bc at the end the output is not
what Id expect.

grocery_items = {“oranges” => False, “bananas” => false, “milk”=> false,
“cream” => false, “beef” => false}
puts “Do you need:”
grocery_items.each do | item, need_for_item |
puts item + “? (Y/N)”
case gets
when “Y/n”
grocery_items[item] = true
when “N/n”
grocery_items[item] = false
end
end
puts “Here is your list:”
grocery_items.each do | item, need_for_item |
puts item if need_for_item
end

Results
Here is your list:
=> {“oranges”=>false, “bananas”=>false, “milk”=>false, “cream”=>false,
“beef”=>false}

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs