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 trialSimon Goldman
1,028 PointsStore_method
not sure why the store method isnt working over here for this objective??
grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company" }
if grocery_item.has_value?("Bread")
grocery_item.store("food" = true)
end
1 Answer
William Li
Courses Plus Student 26,868 Pointsyou shouldn't need to use a method call on the Hash here, a simple bracket notation will do
if grocery_item.has_value?("Bread")
grocery_item["food"] = true
end
If you wonder why the .store() didn't work in your code, that's because the syntax isn't correct. This method takes 2 arguments, with a comma as separator in between. https://ruby-doc.org/core-2.2.0/Hash.html#method-i-store-label-Element+Assignment