Should I use ?
我应该用吗?
{ :first_name => "Mathieu", :last_name => "Jackson" }
or
{ first_name: "Mathieu", last_name: "Jackson" }
4 个解决方案
#1
7
There is no difference between the two, so it is personal preference. Though I would expect most people writing new code for 2.0 will use the second format.
这两者没有区别,所以这是个人偏好。虽然我希望大多数人编写2.0的新代码都会使用第二种格式。
It's important to note that if you are developing for open-source / public consumption and want a wide user base you should use the "old" style of hashes. Ruby 1.8.x, as well as JRuby and other ruby implementations apart from RMI, does not support the terse syntax.
重要的是要注意,如果您正在开发开源/公共消费并希望拥有广泛的用户群,则应使用“旧”样式的哈希值。 Ruby 1.8.x,以及除RMI之外的JRuby和其他ruby实现,不支持简洁的语法。
#2
2
There's no "should".
没有“应该”。
I prefer the 1.9 syntax unless there are symbols-as-values, then I think it looks silly.
我更喜欢1.9语法,除非有符号作为值,然后我觉得它看起来很傻。
This means I don't use them uniformly, it depends on what the hash values are–but I always use the same style in a single immediate hash.
这意味着我不统一使用它们,它取决于哈希值是什么 - 但我总是在一个立即哈希中使用相同的样式。
#3
2
The first one should be using if you are looking for backwards compatibility. But the second one is neater.
如果您正在寻找向后兼容性,则应使用第一个。但第二个是整洁的。
#4
1
Use what you want. There is no sacred meaning in that. But it is highly recommended to use it uniformly.
用你想要的。那里没有神圣的意义。但强烈建议统一使用它。
#1
7
There is no difference between the two, so it is personal preference. Though I would expect most people writing new code for 2.0 will use the second format.
这两者没有区别,所以这是个人偏好。虽然我希望大多数人编写2.0的新代码都会使用第二种格式。
It's important to note that if you are developing for open-source / public consumption and want a wide user base you should use the "old" style of hashes. Ruby 1.8.x, as well as JRuby and other ruby implementations apart from RMI, does not support the terse syntax.
重要的是要注意,如果您正在开发开源/公共消费并希望拥有广泛的用户群,则应使用“旧”样式的哈希值。 Ruby 1.8.x,以及除RMI之外的JRuby和其他ruby实现,不支持简洁的语法。
#2
2
There's no "should".
没有“应该”。
I prefer the 1.9 syntax unless there are symbols-as-values, then I think it looks silly.
我更喜欢1.9语法,除非有符号作为值,然后我觉得它看起来很傻。
This means I don't use them uniformly, it depends on what the hash values are–but I always use the same style in a single immediate hash.
这意味着我不统一使用它们,它取决于哈希值是什么 - 但我总是在一个立即哈希中使用相同的样式。
#3
2
The first one should be using if you are looking for backwards compatibility. But the second one is neater.
如果您正在寻找向后兼容性,则应使用第一个。但第二个是整洁的。
#4
1
Use what you want. There is no sacred meaning in that. But it is highly recommended to use it uniformly.
用你想要的。那里没有神圣的意义。但强烈建议统一使用它。