问题
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
#=>the only correct way or is preferred,# =>is preferred, or- 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