Skip to content

Latest commit

 

History

History
 
 

ruby

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Ruby

Sample

  • Avoid conditional modifiers (lines that end with conditionals).
  • Avoid multiple assignments per line (one, two = 1, 2).
  • Avoid organizational comments (# Validations).
  • Avoid ternary operators (boolean ? true : false). Use multi-line if instead to emphasize code branches.
  • Avoid explicit return statements.
  • Avoid using semicolons.
  • Avoid bang (!) method names. Prefer descriptive names.
  • Don't use self explicitly anywhere except class methods (def self.method) and assignments (self.attribute =).
  • Prefer nested class and module definitions over the shorthand version Example
  • Prefer detect over find.
  • Prefer select over find_all.
  • Prefer map over collect.
  • Prefer reduce over inject.
  • Prefer double quotes for strings.
  • Prefer && and || over and and or.
  • Prefer ! over not.
  • Prefer &:method_name to { |item| item.method_name } for simple method calls.
  • Prefer if over unless.
  • Use _ for unused block parameters.
  • Prefix unused variables or parameters with underscore (_).
  • Use %{} for single-line strings needing interpolation and double-quotes.
  • Use {...} for single-line blocks. Use do..end for multi-line blocks.
  • 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, not def Class.method or class << self.
  • Use def with parentheses when there are arguments.
  • Don't use spaces after required keyword arguments. Example
  • Use each, not for, for iteration.
  • Use a trailing comma after each item in a multi-line list, including the last item. Example
  • Use heredocs for multi-line strings.
  • Prefer protected over private for non-public attr_readers, attr_writers, and attr_accessors.
  • Order class methods above instance methods.