冒号 ":" 和有什么区别?和粗箭头“=" [英] What's the difference between colon ":" and fat arrow "=>"
本文介绍了冒号 ":" 和有什么区别?和粗箭头“="的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Ruby 中的冒号 :
和粗箭头 =>
有什么区别?或者什么时候用什么?
What's the difference between colon :
and fat arrow =>
in Ruby? Or when to use what?
:foo => true
foo: true
推荐答案
语法用于定义 Hash 键/值对,不同取决于 Ruby 版本.
The syntax is for defining Hash key/value pairs, and the difference depends on the Ruby version.
Ruby 1.8 和 Ruby 1.9 均支持
Supported in both Ruby 1.8 and Ruby 1.9
:foo => true
仅在 Ruby 1.9 中支持
Supported only in Ruby 1.9
foo: true
如果您使用 Ruby 1.9 进行开发,您可能应该使用以下语法:
If you're developing in Ruby 1.9 you should probably use the syntax:
foo: true
因为这似乎是社区前进的方向.
as it appears to be the direction the community is moving in.
这篇关于冒号 ":" 和有什么区别?和粗箭头“="的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文