Do not use default positional arguments.
Use keyword arguments (if available - in Ruby 2.0 or later) or an options
hash instead.[link]# bad
def obliterate(things, gently = true, except = [], at = Time.now)
...
end
# good
def obliterate(things, gently: true, except: [], at: Time.now)
...
end
# good
def obliterate(things, options = {})
options = {
:gently => true, # obliterate with soft-delete
}.merge(options)
...
end
Avoid single-line methods. Although
they are somewhat popular in the wild, there are a few peculiarities about
their definition syntax that make their use undesirable.
[link]# bad
def too_much; something; something_else; end
# good
def some_method
# body
end
Method calls
If the first argument to the method uses
parentheses.[]# bad
put! (x + y) % len, value
-
# bad
f (3 + 2) + 1
# good
f(3 + 2) + 1
Omit parentheses for a method call if the
method accepts no arguments.[]If the method doesn’t return a value (or we
don’t care about the return), parentheses are optional. (Especially if the
arguments overflow to multiple lines, parentheses may add readability.)
[]# okay
render(:partial => 'foo')
# okay
render :partial => 'foo'