- Avoid conditional modifiers (lines that end with conditionals). 36491dbb9
- Avoid multiple assignments per line (
one, two = 1, 2
). #109 - Avoid organizational comments (
# Validations
). #63 - Avoid ternary operators (
boolean ? true : false
). Use multi-lineif
instead to emphasize code branches. 36491dbb9 - Avoid explicit return statements. #48
- Avoid using semicolons. #108
- Avoid bang (!) method names. Prefer descriptive names. #122
- Don't use
self
explicitly anywhere except class methods (def self.method
) and assignments (self.attribute =
). #89 - Prefer nested class and module definitions over the shorthand version Example #332
- Prefer
detect
overfind
. 0d819844 - Prefer
select
overfind_all
. 0d819844 - Prefer
map
overcollect
. 0d819844 - Prefer
reduce
overinject
. #237 - Prefer double quotes for strings. #174
- Prefer
&&
and||
overand
andor
. #153 - Prefer
!
overnot
. #195 - Prefer
&:method_name
to{ |item| item.method_name }
for simple method calls. #183 - Prefer
if
overunless
. #254 - Use
_
for unused block parameters. 0d819844 - Prefix unused variables or parameters with underscore (
_
). #335 - Use a leading underscore when defining instance variables for memoization. #373
- Use
%{}
for single-line strings containing double-quotes that require interpolation. 36491dbb9 - Use
{...}
for single-line blocks. Usedo..end
for multi-line blocks. 0d819844 - Use
?
suffix for predicate methods. 0d819844 - Use
CamelCase
for classes and modules,snake_case
for variables and methods,SCREAMING_SNAKE_CASE
for constants. 36491dbb9 - Use
def self.method
, notdef Class.method
orclass << self
. 40090e22 - Use
def
with parentheses when there are arguments. 36491dbb9 - Don't use spaces after required keyword arguments. Example #205
- Use
each
, notfor
, for iteration. 36491dbb9 - Use a trailing comma after each item in a multi-line list, including the last item. Example #167
- Use heredocs for multi-line strings. 36491dbb9
- Prefer
private
overprotected
for non-publicattr_reader
s,attr_writer
s, andattr_accessor
s. #417, #190 - Order class methods above instance methods. #320
- Prefer method invocation over instance variables. #331
ruby
Folders and files
Name | Name | Last commit date | ||
---|---|---|---|---|
parent directory.. | ||||