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

William Lynch
William Lynch
5,636 Points

ruby values_at challenge

I can't get the ruby values_at challenge. I've tried all the answers in the forum, but no luck. Please let me know the answer. Make sure to run it on the challenge first.

Thanks, Bill

grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }

grocery_list=[grocery_item.values_at("item")]

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




grocery_list=[grocery_item.values_at("item")]

Have you tried removing the brackets around the grocery_item.values_at("item")? The values_at(key) already returns an array, so the [] brackets are not needed.

William Lynch
William Lynch
5,636 Points

Still doesn't work. I block copied into the challenge. By the way, I challenge 1 with no problem. The error comes when I make the grocery_list array.

1 Answer

Michael Hess
Michael Hess
24,512 Points

Hi Bill,

You don't have to put grocery_item.values_at("item") in brackets.

Try this:

grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }

#task 2
if grocery_item.has_value?("Bread")
  grocery_item["food"] = true
end

#task 1
grocery_list = grocery_item.values_at("item")

If you have any questions feel free to ask! Hope this helps!

William Lynch
William Lynch
5,636 Points

Yes, I've tried that too. No luck.