“冒号”与“冒号”之间的区别是什么?和胖箭头“=”>“ [英] What's the difference between colon ":" and fat arrow "=>"

查看:212
本文介绍了“冒号”与“冒号”之间的区别是什么?和胖箭头“=”>“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ruby中的冒号和胖箭头 => 有什么区别?或者何时使用什么?

What's the difference between colon : and fat arrow => in Ruby? Or when to use what?

:foo => true
foo: true


推荐答案

用于定义哈希键/值对,差别取决于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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆