Skip to content

Commit fe295a7

Browse files
committed
Extract method-related rules into own section
1 parent 2bda235 commit fe295a7

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

STYLEGUIDE.md

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ This is GitHub's Ruby Style Guide, inspired by [RuboCop's guide][rubocop-guide].
2020
12. [Regular Expressions](#regular-expressions)
2121
13. [Requires](#requires)
2222
14. [Strings](#strings)
23-
15. [Syntax](#syntax)
23+
15. [Methods](#methods)
24+
1. [Method definitions](#method-definitions)
25+
2. [Method calls](#method-calls)
26+
27+
16. [Syntax](#syntax)
2428

2529
## Layout
2630

@@ -558,7 +562,9 @@ paragraphs.each do |paragraph|
558562
end
559563
```
560564

561-
## Syntax
565+
## Methods
566+
567+
### Method definitions
562568

563569
* Use `def` with parentheses when there are arguments. Omit the
564570
parentheses when the method doesn't accept any arguments.
@@ -573,6 +579,24 @@ end
573579
end
574580
```
575581

582+
### Method calls
583+
584+
* If the first argument to a method begins with an open parenthesis,
585+
always use parentheses in the method invocation. For example, write
586+
`f((3 + 2) + 1)`.
587+
588+
* Never put a space between a method name and the opening parenthesis.
589+
590+
``` ruby
591+
# bad
592+
f (3 + 2) + 1
593+
594+
# good
595+
f(3 + 2) + 1
596+
```
597+
598+
## Syntax
599+
576600
* Never use `for`, unless you know exactly why. Most of the time iterators
577601
should be used instead. `for` is implemented in terms of `each` (so
578602
you're adding a level of indirection), but with a twist - `for`
@@ -779,20 +803,6 @@ enabled = true if enabled.nil?
779803
one-liner scripts is discouraged. Prefer long form versions such as
780804
`$PROGRAM_NAME`.
781805

782-
* Never put a space between a method name and the opening parenthesis.
783-
784-
``` ruby
785-
# bad
786-
f (3 + 2) + 1
787-
788-
# good
789-
f(3 + 2) + 1
790-
```
791-
792-
* If the first argument to a method begins with an open parenthesis,
793-
always use parentheses in the method invocation. For example, write
794-
`f((3 + 2) + 1)`.
795-
796806
* Use `_` for unused block parameters.
797807

798808
``` ruby

0 commit comments

Comments
 (0)