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

I am getting an error that says "The `has_value?` method was not called." But I am calling it clearly in my code.

I am stuck. If it's user error can someone please tell me what I'm missing here? Thanks!

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

value_available = grocery_item.has_value?("Bread")

if value_available
  grocery_item = { "food" => true }
end

2 Answers

Hey Peter, you are calling the has_value? method correctly. You are not assigning a key/value property on a hash correctly in your if statement. Review how key/value properties are created on a hash in Ruby and you should be good. Good luck. I hope this helps.

Thanks Tyler! I got it working after bashing my head against the wall for a little bit

No worries, Peter! I know what you mean. I've done my fair share of head bashing! Good luck!