Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我尝试做
assert_equal { dry: true }, res
我明白了
syntax error, unexpected ':', expecting '}' assert_equal { dry: true }, res
但
assert_equal({ dry: true }, res)
工作正常。为什么第一种形式不足以让 ruby 理解我的意思?或者更准确地说,Ruby 认为我想要做什么?
在第一个示例中,花括号被解释为分隔块。由于dry: true不是合法表达式,因此您会得到一个SyntaxError.
dry: true
SyntaxError