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 trialCagdas Yigit
2,159 PointsUsing the values_at method, create an array called grocery_list with the value of the grocery_item hash at the "item" ke
a
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
grocery_list = {"item" => "grocery_item"}
if grocery_item.has_value?("Bread")
grocery_item.store("food" ,true)
end
grocery_list.values_at("item")
2 Answers
Luke Pettway
16,593 PointsAlmost, you need to call the push() method and then assign it using the values_at() method of the grocery_item to the key item.
grocery_list.push(grocery_item.values_at("item"))
Cagdas Yigit
2,159 PointsThanx
Ira Salem
10,331 PointsIra Salem
10,331 PointsHere is my code but once I put in the line of code like you have it tells me this: "Oops! It looks like Task 1 is no longer passing."
Ira Salem
10,331 PointsIra Salem
10,331 PointsI even tried it with the asker's code with your code. Still says the same thing.
Luke Pettway
16,593 PointsLuke Pettway
16,593 PointsI think I had a different bit of code at the top for my original answer to work, here is an updated solution that will work based on what you have for your code:
Ira Salem
10,331 PointsIra Salem
10,331 PointsAwesome! That worked. Do you know why my previous code wouldn't work by chance?
Luke Pettway
16,593 PointsLuke Pettway
16,593 PointsThe first set of code needed the if block and the second one, I think it was how I structured grocery list when I was going back to answer the question, I think I had it set as an array instead of a hash, which is why push would have worked.
It was my mistake for not pasting all of my working code.