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

has_value? method was not called

I have used the has_value method but still i am getting the error that i havent?

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


if grocery_item.has_value?("Bread")
     grocery_item ={"food" => true}
end

2 Answers

Antonio De Rose
Antonio De Rose
20,885 Points

4 errors

I would suggest you to go through the video again and again

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

if grocery_item.has_value?("Bread")
     grocery_item ={"food" => true} # 1) you are missing the function after, grocery_item, which adds key values
# 2) you do not use an equal operator here
# 3) no curly braces, but another brace
# 4) no arrow operator, it should be another
end
Kevin Singleton
Kevin Singleton
6,833 Points

Set the grocery_item ["food"] = true In the if block Ruby doesn't know what you mean When you say grocery_item = {"food" => true }