Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Collections Ruby Hashes Working with Hash Values

Juan Ordaz
Juan Ordaz
12,012 Points

I don't think I understand the question

Do I suppost to use the Bread value on the array???

hash.rb
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company", "food" => true}
grocery_item.has_value?("Bread")
grocery_list = ["Bread"]
grocery_list.values_at("Bread")

2 Answers

If you're asking about task 2, they want you to write something like grocery_list = grocery_item.values_at 'item'

It's a weird question, because using values_at with a single argument is very similar to just using grocery_item['item'], except that what you get back is an array. I guess the idea is that you're starting a grocery list with a single new thing... but it's really stretching the bounds of what makes a realistic programming exercise.

For task 1, they are just asking you to check if the item is bread, in which case you'll add a new detail to the item, which is to say that it truly is food:

if grocery_item.has_value? 'Bread'
  grocery_item['food'] = true
end
Juan Ordaz
Juan Ordaz
12,012 Points

Thank you for your help. Although, I understand the concept, I struggle to understand the question.