Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CMD中出现Ruby脚本中的语法错误_Ruby - Fatal编程技术网

CMD中出现Ruby脚本中的语法错误

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

我不知道为什么每次在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

请让我知道它出了什么问题,因为我已经检查了数千次&什么也没发现

应该使用大括号(
{}
)来定义散列对象:

hash_brown = {
    "topping_1" => "Sour Cream",
    "topping_2" => "Butter",
    "topping_3" => "Salt",
    "topping_4" => "Ketchup"
}

在Ruby中,文本哈希是由
{}
大括号绑定的,而不是由
()
括号绑定的
hash_brown={…}
你认为
$end
在做什么?它没有理由出现在那里。