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 Build a Grocery List Program Working with Hashes That Contain Arrays

I think that this challenge is still buggy.

Ruby Collections code challenge 1 of 1 adding grocery_item to grocery_list "item" array answer: grocery_list = grocery_item.values_at("items") However, it will fail no matter what alterations/refreshes I attempt. I've read that this has been brought to attention previously; should I skip this or is there a way to override the error to pass? Would love some help on this. Thank you

grocery_list = { 'title' => 'Grocery List', 'items' => [] }
grocery_item = { 'title' => 'Bread', 'quantity' => 1 }

grocery_list = grocery_item.values_at("items")

2 Answers

William Li
William Li
Courses Plus Student 26,868 Points

Hi there, the challenge, as it's right now, has not bug.

The problem here is that in your solution grocery_list = grocery_item.values_at("items"), the assignment operator = was used on grocery_list hash, doing so will assign an entirely new value to it, which isn't what the challenge is asking for.

The code challenge essentially wants you to retrieve the Array value associated with the items key from the grocery_list, then append grocery_item hash to the end of the Array.

One way to accomplish that is by using the push method in the Array class.


The use of push method was covered in this lecture.

Hah! Woops, of course it does. Thanks for getting back to me so quick William- I must have not understood the question(i've been using the push method for sometime in my own projects!). Anyway, glad the challenge isn't bugged; now I can complete it! Have a good one :)