-
Notifications
You must be signed in to change notification settings - Fork 7
Style Guide
Kevin edited this page Jan 26, 2017
·
6 revisions
- Avoid inline conditionals:
return 5 if something?
- Avoid multiple variable assignments per line
one, two = 1, 2
- Avoid ternary operators (
boolean ? true : false
) - Don't use
self
explicitly anywhere except class methods (def self.method
) and assignments (self.attribute =
). - Prefer
select
overfind_all
. - Prefer
map
overcollect
. - Prefer
reduce
overinject
. - Prefer single quotes for strings.
- Prefer
&&
and||
overand
andor
. - Prefer
!
overnot
. - Prefer
&:method_name
to{ |item| item.method_name }
for simple method calls. - Don't use
unless
. Useif
. - Use
_
for unused block parameters. - Prefix unused variables or parameters with underscore (
_
). - Always use
do..end
. - Use
?
suffix for predicate methods. - Use
CamelCase
for classes and modules,snake_case
for variables and methods,SCREAMING_SNAKE_CASE
for constants. - Use
def self.method
orclass << self
for static methods but they should generally be avoided. - Use
def
with parentheses when there are arguments. Same for function calls. - Use
each
, notfor
, for iteration. - Use a trailing comma after each item in a multi-line list, including the last item.
[
'a',
'b',
]
- Prefer
private
overprotected
for non-publicattr_reader
s,attr_writer
s, andattr_accessor
s. - Order class methods above instance methods.
- Prefer method invocation over instance variables.
- Avoid at all cost to make a method longer than 10LOC.
- Don't use
before_action
especially multiple actions, use explicit functions. - For configuration, create a yaml file in config/ and parse it in an initializer.
- Place logic in services/. Please use Interactor.
- Avoid
where("x > ?", num_var)
placeholders, usewhere("x > :num", { num: num_var })
. Especially for larger numbers of parameters.
- Don't ever use float yourself, for this kind of layout constraint, refer to the bootstrap documentation on layout