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

daniwao
daniwao
13,125 Points

Adding to Ruby Hash

I'm not sure what I'm doing wrong here. It seems to me that I'm supposed to create a new temp_hash and then give it the key/value pair and then append it to the end of the grocery_item hash.

1 Answer

Ricky Walker
Ricky Walker
12,863 Points

Hi Dan. When adding items to a hash, you can use bracket notation with the name of the hash. For instance, if you want to add to the grocery_item hash, you'd use:

grocery_item[:item2] = "eggs"

I'm not sure if this completely answers your question because I can't see your code or the problem you're working on. Let me know if this provides some insight or if you have to use different notation.

daniwao
daniwao
13,125 Points

Thanks Ricky. That's basically what I was wondering. I was using a merge. Here's my final code below that got it to pass. Thanks again!

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