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

stuck on ruby collections

I know I'm missing something, but I can't figure what it is. Any ideas?

hash.rb
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }

if (grocery_item.has_value?("Bread"))
  puts grocery_item.unshift["food" => true]
end

3 Answers

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Robert,

Inside your if condition try assigning "food" to true this way without puts.

grocery_item["food"] = true

I hope this helps.

Hi Robert,

Seems very close but I think Jason Seifer already explained about "store" - @4:08. Other thing is to remove some brackets and don't have to use "puts" that will do automatically by using store method to add key/value to the hash.

Example:

grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }

if grocery_item.has_value?("Bread")
  grocery_item.store("food", true)
end

Hope that helps

Yes It did work! Thank you Justin. Now I'm confuse on why my method didn't work. I'll look up the 'store' method right after this Salman. Thank you both.

Awesome, happy coding! :smile: