[英]New Ruby syntax doesn't work everytime
I would like to ask Ruby experts for explaination. 我想请Ruby专家进行解释。
I can't use something like "foo-bar": true
, but foobar: true
works. 我不能使用
"foo-bar": true
,但是foobar: true
可以的。 Did anyone notice this? 有人注意到吗?
In new Ruby syntax we can replace this hash rocket: 在新的Ruby语法中,我们可以替换此哈希火箭:
<%= f.submit "Save", :class => "btn" %>
^-------------^
with this 有了这个
<%= f.submit "Save", class: "btn" %>
^----------^
Now, how about symbols with two words? 现在,两个单词的符号怎么样? This doesn't work - syntax error!
这不起作用-语法错误!
<%= f.submit "Save", "data-disable-with": "Saving..." %>
^------------------------------^
The JSON style Hash
syntax is for Hash
es whose keys are Symbol
s which are valid Ruby identifiers. JSON样式
Hash
语法适用于Hash
其键是Symbol
,它们是有效的Ruby标识符。 Your key is neither a Symbol
(it's a String
) nor a valid Ruby identifier (Ruby identifiers cannot contain a hyphen, because that creates an ambiguity with the binary infix -
operator: does ab
mean the identifier ab
or does it mean "subtract b
from a
, ie a.-(b)
?) 你的关键既不是一个
Symbol
(这是一个String
),也不是有效的Ruby标识符(Ruby的标识符不能包含一个连字符,因为它创建与二进制中缀的模糊性-
运营商:不ab
意味着标识符ab
还是意味着“减去b
从a
,即a.-(b)
?)
您试图将密钥设置为字符串而不是符号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.