diff --git a/README.md b/README.md index aefd462..a096af9 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ Translations of the guide are available in the following languages: * [Naming](#naming) * [Comments](#comments) * [Comment Annotations](#comment-annotations) + * [Magic Comments](#magic-comments) * [Classes & Modules](#classes--modules) * [Exceptions](#exceptions) * [Collections](#collections) @@ -401,6 +402,88 @@ Translations of the guide are available in the following languages: end ``` +* + Don't use several empty lines in a row. +[[link](#two-or-more-empty-lines)] + + ```Ruby + # bad - It has two empty lines. + some_method + + + some_method + + # good + some_method + + some_method + ``` + +* + Use empty lines around access modifiers. +[[link](#empty-lines-around-access-modifier)] + + ```Ruby + # bad + class Foo + attr_reader :foo + def foo + # do something... + end + end + + # good + class Foo + attr_reader :foo + + def foo + # do something... + end + end + ``` + +* + Don't use empty lines around method, class, module, block bodies. +[[link](#empty-lines-around-bodies)] + + ```Ruby + # bad + class Foo + + def foo + + begin + + do_something do + + something + + end + + rescue + + something + + end + + end + + end + + # good + class Foo + def foo + begin + do_something do + something + end + rescue + something + end + end + end + ``` + * Avoid comma after the last parameter in a method call, especially when the parameters are not on separate lines. @@ -1028,7 +1111,7 @@ Translations of the guide are available in the following languages: ok = got_needed_arguments and arguments_are_valid # control flow - document.save or fail(RuntimError, "Failed to save document!") + document.save or fail(RuntimeError, "Failed to save document!") # good # boolean expression @@ -2470,6 +2553,24 @@ no parameters. end ``` +* + Split multiple mixins into separate statements. +[[link](#mixin-grouping)] + + ```Ruby + # bad + class Person + include Foo, Bar + end + + # good + class Person + # multiple mixins go in separate statements + include Foo + include Bar + end + ``` + * Don't nest multi-line classes within classes. Try to have such nested classes each in their own file in a folder named like the containing class. @@ -2934,7 +3035,7 @@ no parameters. leading `self` or own name followed by a `.` when calling other such methods. This is often seen in "service classes" or other similar concepts where a class is treated as though it were a function. This convention tends to reduce - repetitive boilerpate in such classes. + repetitive boilerplate in such classes. [[link](#class-and-self)] ```Ruby @@ -3868,7 +3969,7 @@ resource cleanup when possible. ``` * - Avoid %() or the equivlant %q() unless you have a string with both `'` and + Avoid %() or the equivalent %q() unless you have a string with both `'` and `"` in it. Regular string literals are more readable and should be preferred unless a lot of characters would have to be escaped in them. [[link](#percent-q)]