rubyist icon indicating copy to clipboard operation
rubyist copied to clipboard

coding style: single line method definitions

Open riffraff opened this issue 14 years ago • 1 comments

I wonder if there is consensus on how/when to use single line method definitions. E.g.

  def foo() bar end
  vs
  def foo; bar; end

It's a small thing, and I'd say it makes sense to point out that usually it's just better to avoi them. Although I write them all the time :)

riffraff avatar Sep 19 '11 20:09 riffraff

This is an interesting point.

I personally suggest to avoid one-line definition, even if methods are empty like the case of very simple Rails controllers. The only situation where one-line definitions are allowed is in tests, in case you need to create a class on the fly for specific tests.

I'll add a paragraph to the documentation.

weppos avatar Sep 20 '11 08:09 weppos