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 Keys

'If it does, set a new variable called food to true' - I am unable to perform this section of the task.

I tried all the possible ways to set food to tue in this task but cannot.

hash = { "name" => "Bread", "quantity" => 1, "calories" => 100 }
hash.store("food", "true")

2 Answers

Hi there,

You can do this on one line, or multiple. The conditional test uses has_key? on hash using dot notation. Pass in "calories" either in the brackets or without them.

Around that, you can either use an if and end before & after, setting food = true inside that block. Or, you can just do this on one line by saying food = true if condition - the condition is the test above.

I hope that helps,


thank you so much

No problem! :+1: