@@ -20,7 +20,11 @@ This is GitHub's Ruby Style Guide, inspired by [RuboCop's guide][rubocop-guide].
20
20
12 . [ Regular Expressions] ( #regular-expressions )
21
21
13 . [ Requires] ( #requires )
22
22
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 )
24
28
25
29
## Layout
26
30
@@ -558,7 +562,9 @@ paragraphs.each do |paragraph|
558
562
end
559
563
```
560
564
561
- ## Syntax
565
+ ## Methods
566
+
567
+ ### Method definitions
562
568
563
569
* Use ` def ` with parentheses when there are arguments. Omit the
564
570
parentheses when the method doesn't accept any arguments.
573
579
end
574
580
```
575
581
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
+
576
600
* Never use ` for ` , unless you know exactly why. Most of the time iterators
577
601
should be used instead. ` for ` is implemented in terms of ` each ` (so
578
602
you're adding a level of indirection), but with a twist - ` for `
@@ -779,20 +803,6 @@ enabled = true if enabled.nil?
779
803
one-liner scripts is discouraged. Prefer long form versions such as
780
804
` $PROGRAM_NAME ` .
781
805
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
-
796
806
* Use ` _ ` for unused block parameters.
797
807
798
808
``` ruby
0 commit comments