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 trialSam Fitz
7,036 PointsHow to insert a Hash into an Array, which is itself also inside a Hash? (in Ruby)
I'm afraid I'm quite lost on how to do this. There was some usage of the .each command in the video leading up to this challenge, but even that I have a tentative grasp on, and this seems to be territory that wasn't even directly touched in the video.
Any help would be appreciated. I've done several Google searches, but haven't been able to find any instances where someone is asking about how to insert a Hash into an Array which is in a Hash....
grocery_list = { 'title' => 'Grocery List', 'items' => [] }
grocery_item = { 'title' => 'Bread', 'quantity' => 1 }
items = [{grocery_item}]
2 Answers
Maciej Czuchnowski
36,441 PointsI think this will answer you: https://teamtreehouse.com/forum/issues-adding-a-hash-into-an-array
Sam Fitz
7,036 PointsMaciej, you came through for me again! Thank you!
And I'm glad the solution is simple and elegant compared to what I presumed.