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.
冒号哈希语法有效:
{ abc: 5 } # => {:abc=>5}
但是,puts {abc: 5}会引发错误:
puts {abc: 5}
syntax error, unexpected ':', expecting '}' puts {abc: 5} ^
我正在使用红宝石 2.0.0。为什么会这样?
被{}识别为一个块。把它放在括号里。
{}
puts({abc: 5})
或者
puts(abc: 5)
puts abc: 5