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.rb
hash = { "name" => "Bread", "quantity" => 1, "calories" => 100 }
hash.has_key?("calories")
hash.store("food", "true")

2 Answers

Steve Hunter
MOD
Steve Hunter
Treehouse Moderator 56,737 Points

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,

Steve.

thank you so much