Indent with two spaces, never tabs.
# bad
def foo
# indented with tabs
end
# good
def bar
# indented with spaces
end
Use Unix-style line endings.
The following should always be surrounded by spaces: = + - % / && || { }
The following should never be surrounded by spaces: ( ) [ ]
Always end a file with a new line.
Always parenthesize argument lists:
def foo(x, y)
# ...
end
z = foo(1, 2)
Unless you're working with a DSL:
# Gemfile
gem "rails", "3.2.12"
Use the stabby lambda syntax ->(x, y) { x + y }
instead of Proc.new
unless it's really necessary.
Use do...end
for multi-line blocks, { ... }
for one-liners.
Don't chain blocks unless you really need to. Use intermediates instead.
Use double quotes instead of single quotes.
Use parens to for %w
and friends, not curlies or squares.
Prefer whitespace arrays when you need an array of strings:
%w(a b c d) # not ["a", "b", "c", "d"]
Use these enumerable methods: map, inject, select, detect