Frage

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?

War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top