Ruby Ruby Collections Ruby Hashes Working with Hash Keys

hash = { "name" => "Bread", "quantity" => 1, "calories" => 100 } if ( hash.has_key?("calories") )

Is this not correct: hash = { "name" => "Bread","quantity" => 1,"calories" => 100 } if (has.has_key?("calories") ) hash.store("", true)

hash.rb
hash = { "name" => "Bread", "quantity" => 1, "calories" => 100 }
if ( hash.has_key?("calories") )
  hash.store("food", true)
end 

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,429 Points

Please note that they want you to create a variable, not a hash key and value.

if hash.has_key?("calories")
  food = true
end

Thank you.