我不知道为什么每当我在CMD中运行此代码时,我都会收到此错误:
语法错误,意外=>
这是我的代码:
hash_brown = (
"topping_1" => "Sour Cream",
"topping_2" => "Butter",
"topping_3" => "Salt",
"topping_4" => "Ketchup"
)
puts hash_brown["topping_2"]
first_hash = Hash.new
first_hash["first_name"] = "Jacob"
first_hash["nick_name"] = "Day"
first_hash["last_name"] = "Williams"
puts first_hash["first_hash"]
$end
请让我知道它有什么问题因为我已经检查了几千次&没找到任何东西!
答案 0 :(得分:0)
您应该使用花括号({}
)来定义哈希对象:
hash_brown = {
"topping_1" => "Sour Cream",
"topping_2" => "Butter",
"topping_3" => "Salt",
"topping_4" => "Ketchup"
}