Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!

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

value_available = grocery_item.has_value?("Bread")

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

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!