The `#=>` convention for expected returns

点点圈 提交于 2020-01-06 03:50:09

问题


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. #=> 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?


回答1:


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 #

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 #=>.



来源:https://stackoverflow.com/questions/13107492/the-convention-for-expected-returns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!