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 Hash Methods

Hadas Cassorla
Hadas Cassorla
1,382 Points

To create new hash containing the contents of two hashes merged, I wrote: new{hash1.merge(hash2)} why's this wrong

I also tried the attached code as an alternative. I am not sure what's missing here.

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

final_item = Hash.new 
final_item[grocery_item.merge(calories)]

1 Answer

Hello,

You're close to completing this challenge. The merge function takes the hash you give it and merges it with the one you are calling it on returning the merged hash. So once you use the merge function, you just need to assign it to final_item instead of trying to index the merged hash and you should be able to pass the challenge. If you need further assistance, please let us know and we can help you further. Please also provide your updated code so we can assist you from the point you are at.