Coding Standards

Formatting

  • No lines longer than 79 characters (for visualization on 80 columns, leaving one for the '+' and '-' of diffs)
  • 2-space indentation
  • {} for blocks where the return value is important, do-end when it isn't
  • single quotes on all string literals unless you're doing interpolation
  • 1 empty line before and after multiline code blocks (including ifs and stuff). If they're of the same type, nested with nothing between the many "do"/"{"s and "end"/"}"s, do this only for the outermost block
  • 2 empty lines between top-level statements/blocks (stuff that's not inside any class/module, i.e., not indented)
  • 1 empty line before comments
  • 1 space after the '#' in a comment
  • no inline comments (except on the rarest of cases)
  • newline after "class" and before the class's "end"
  • no need for "if ... then"; only "if" is enough

File layout

Model layout should follow this order:

  • fields (when using HoboFields?)
  • plugins (acts_as_whatever, etc.)
  • associations
  • validations
  • callbacks
  • named_scopes
  • class methods
  • instance methods

Commits

  • one short, descriptive line (preferably < 72 characters)
  • one blank line
  • more detailed explanation (if needed)

Back to Project Guidelines