Ruby Ruby Collections Ruby Hashes Working with Hash Values

geet bhullar
geet bhullar
953 Points

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,858 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 }