CMD中出现Ruby脚本中的语法错误
我不知道为什么每次在CMD中运行此代码时,都会出现以下错误: 语法错误,意外=> 这是我的密码:CMD中出现Ruby脚本中的语法错误,ruby,Ruby,我不知道为什么每次在CMD中运行此代码时,都会出现以下错误: 语法错误,意外=> 这是我的密码: hash_brown = ( "topping_1" => "Sour Cream", "topping_2" => "Butter", "topping_3" => "Salt", "topping_4" => "Ketchup" ) puts hash_brown["topping_2"] first_hash = Hash.ne
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
请让我知道它出了什么问题,因为我已经检查了数千次&什么也没发现 应该使用大括号(
{}
)来定义散列对象:
hash_brown = {
"topping_1" => "Sour Cream",
"topping_2" => "Butter",
"topping_3" => "Salt",
"topping_4" => "Ketchup"
}
在Ruby中,文本哈希是由
{}
大括号绑定的,而不是由()
括号绑定的hash_brown={…}
你认为$end
在做什么?它没有理由出现在那里。