预期收益的“#=>”约定 [英] The `#=>` convention for expected returns

查看:89
本文介绍了预期收益的“#=>”约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ruby惯例是使用#=> 来描述期望的回报。我意识到我自己使用了#=> (带有一些空格或制表符)。这只是一个约定,没有正式的规范,因此我想问一下Ruby程序员中的约定是什么。

It is a Ruby convention to use #=> for describing expected returns. I realized that I use # => (with some space or tabs) myself. This is just a convention, and there is no formal specification, so I would like to ask what the convention is among Ruby programmers. Is


  1. #=> 是唯一正确的方法还是首选,
  1. #=> the only correct way or is preferred,
  2. # => is preferred, or
  3. Either is almost equally used?

并且,是否有任何理由排除或喜欢一种形式?

And, would there be any reasons to exclude or prefer one form?

推荐答案

我不会说这是一个约定。至少我还没有读过任何地方。我之所以使用它,只是因为我的编辑器(TextMate)在评估代码时可以帮助扩展这些标记。例如,如果我键入以下行:

I wouldn't say it's a convention. At least, I haven't read anywhere about it. I use it myself only because my editor (TextMate) helpfully expands these markers when evaluating code. For example, if I type this line:

2 + 3 #

然后按TAB键,它将在哈希字符后插入 => 。该行变为:

And then press TAB, it will insert => after the hash character. The line becomes this:

2 + 3 # =>

然后,如果我按下快捷键,它将运行代码并在之后插入/更新相应行的值#=> 标记。

Then if I press a shortcut, it will run the code and insert/update value of corresponding lines after the # => markers.

2 + 3 # => 5

此外,我个人认为#=> #=> 更具可读性。

Also, I personally think that # => looks much more readable than #=>.

这篇关于预期收益的“#=>”约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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