• Indent as deep as case.
      [link]

    • Align function parameters either all on
      the same line or one per line.[link]

      1. # bad
      2. def self.create_translation(phrase_id, phrase_key, target_locale,
      3. value, user_id, do_xss_check, allow_verification)
      4. ...
      5. end
      6. # good
      7. def self.create_translation(phrase_id,
      8. phrase_key,
      9. target_locale,
      10. value,
      11. user_id,
      12. do_xss_check,
      13. allow_verification)
      14. ...
      15. end
      16. # good
      17. def self.create_translation(
      18. phrase_id,
      19. phrase_key,
      20. target_locale,
      21. value,
      22. user_id,
      23. do_xss_check,
      24. allow_verification
      25. )
      26. ...
      27. end
    • Indent succeeding lines in multi-line
      boolean expressions.[link]

      1. # bad
      2. def is_eligible?(user)
      3. program_not_expired
      4. end
      5. # good
      6. def is_eligible?(user)
      7. Trebuchet.current.launch?(ProgramEligibilityHelper::PROGRAM_TREBUCHET_FLAG) &&
      8. is_in_program?(user) &&
      9. program_not_expired
      10. end
    • Never leave trailing whitespace.
      [link]

    • When making inline comments, include a
      space between the end of the code and the start of your comment.
      [link]

      1. # bad
      2. result = func(a, b)# we might want to change b to c
      3. # good
      4. result = func(a, b) # we might want to change b to c
      1. sum = 1 + 2
      2. a, b = 1, 2
      3. 1 > 2 ? true : false; puts 'Hi'
      4. [1, 2, 3].each { |e| puts e }
    • Never include a space before a comma.
      [link]

    • Do not include space inside block
      parameter pipes. Include one space between parameters in a block.
      Include one space outside block parameter pipes.
      [link]

      1. # bad
      2. {}.each { | x, y |puts x }
      3. # good
      4. {}.each { |x, y| puts x }
    • Do not leave space between ! and its
      argument.[link]

      1. !something
    • No spaces after (, [ or before ], ).
      [link]

      1. some(arg).other
      2. [1, 2, 3].length
    • Omit whitespace when doing
      string interpolation.[link]

      1. var = "This #{ foobar } is interpolated."
      2. var = "This #{foobar} is interpolated."
    • Add a new line after if conditions spanning
      multiple lines to help differentiate between the conditions and the body.
      [link]

      1. if @reservation_alteration.checkin == @reservation.start_date &&
      2. @reservation_alteration.checkout == (@reservation.start_date + @reservation.nights)
      3. redirect_to_alteration @reservation_alteration
      4. end
    • Add a new line after conditionals,
      blocks, case statements, etc.[link]

      1. if robot.is_awesome?
      2. send_robot_present
      3. end
      4. robot.add_trait(:human_like_intelligence)
    • Don’t include newlines between areas
      of different indentation (such as around class or module bodies).
      [link]

      1. # bad
      2. class Foo
      3. def bar
      4. # body omitted
      5. end
      6. end
      7. # good
      8. class Foo
      9. def bar
      10. # body omitted
      11. end
      12. end
    • Include one, but no more than one, new
      line between methods.[link]

      1. def a
      2. end
      3. end
    • Use a single empty line to break between
      statements to break up methods into logical paragraphs internally.
      [link]