Skip to content

Commit 047fae8

Browse files
committed
Updated from the upstream.
1 parent e4a11b9 commit 047fae8

File tree

1 file changed

+103
-14
lines changed

1 file changed

+103
-14
lines changed

README-enUS.md

Lines changed: 103 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ Translations of the guide are available in the following languages:
6868
* [Chinese Simplified](https://github.com/JuanitoFatas/ruby-style-guide/blob/master/README-zhCN.md)
6969
* [Chinese Traditional](https://github.com/JuanitoFatas/ruby-style-guide/blob/master/README-zhTW.md)
7070
* [French](https://github.com/gauthier-delacroix/ruby-style-guide/blob/master/README-frFR.md)
71-
* [German](https://github.com/arbox/de-ruby-style-guide/blob/master/README-deDE.md)
7271
* [Japanese](https://github.com/fortissimo1997/ruby-style-guide/blob/japanese/README.ja.md)
7372
* [Korean](https://github.com/dalzony/ruby-style-guide/blob/master/README-koKR.md)
7473
* [Portuguese (pt-BR)](https://github.com/rubensmabueno/ruby-style-guide/blob/master/README-PT-BR.md)
@@ -217,7 +216,7 @@ Translations of the guide are available in the following languages:
217216
class FooError < StandardError; end
218217
```
219218

220-
The only exception, regarding operators, is the exponent operator:
219+
There are a few exceptions. One is the exponent operator:
221220

222221
```ruby
223222
# bad
@@ -227,6 +226,16 @@ Translations of the guide are available in the following languages:
227226
e = M * c**2
228227
```
229228

229+
Another exception is the slash in rational literals:
230+
231+
```ruby
232+
# bad
233+
o_scale = 1 / 48r
234+
235+
# good
236+
o_scale = 1/48r
237+
```
238+
230239
* <a name="spaces-braces"></a>
231240
No spaces after `(`, `[` or before `]`, `)`.
232241
Use spaces around `{` and before `}`.
@@ -778,7 +787,7 @@ Translations of the guide are available in the following languages:
778787
temperance = Person.new('Temperance', 30)
779788
```
780789

781-
Only omit parentheses for
790+
Always omit parentheses for
782791

783792
* Method calls with no arguments:
784793

@@ -816,13 +825,20 @@ Translations of the guide are available in the following languages:
816825

817826
# body omitted
818827
end
828+
```
819829

820-
# bad
821-
puts(temperance.age)
830+
Can omit parentheses for
831+
832+
* Methods that have "keyword" status in Ruby, but are not declarative:
833+
834+
```Ruby
822835
# good
836+
puts(temperance.age)
837+
system('ls')
838+
# also good
823839
puts temperance.age
840+
system 'ls'
824841
```
825-
826842
* <a name="optional-arguments"></a>
827843
Define optional arguments at the end of the list of arguments.
828844
Ruby has some unexpected results when calling methods that have
@@ -1852,6 +1868,7 @@ no parameters.
18521868

18531869
* <a name="named-format-tokens"></a>
18541870
When using named format string tokens, favor `%<name>s` over `%{name}` because it encodes information about the type of the value.
1871+
<sup>[[link]](#named-format-tokens)</sup>
18551872

18561873
```ruby
18571874
# bad
@@ -1860,7 +1877,6 @@ no parameters.
18601877
# good
18611878
format('Hello, %<name>s', name: 'John')
18621879
```
1863-
<sup>[[link](#named-format-tokens)</sup>
18641880

18651881
* <a name="array-join"></a>
18661882
Favor the use of `Array#join` over the fairly cryptic `Array#*` with
@@ -2626,6 +2642,42 @@ no parameters.
26262642
end
26272643
```
26282644

2645+
* <a name="namespace-definition"></a>
2646+
Define (and reopen) namespaced classes and modules using explicit nesting.
2647+
Using the scope resolution operator can lead to surprising constant lookups
2648+
due to Ruby's [lexical scoping](https://cirw.in/blog/constant-lookup.html),
2649+
which depends on the module nesting at the point of definition.
2650+
<sup>[[link](#namespace-definition)]</sup>
2651+
2652+
```Ruby
2653+
module Utilities
2654+
class Queue
2655+
end
2656+
end
2657+
2658+
# bad
2659+
class Utilities::Store
2660+
Module.nesting # => [Utilities::Store]
2661+
2662+
def initialize
2663+
# Refers to the top level ::Queue class because Utilities isn't in the
2664+
# current nesting chain.
2665+
@queue = Queue.new
2666+
end
2667+
end
2668+
2669+
# good
2670+
module Utilities
2671+
class WaitingList
2672+
Module.nesting # => [Utilities::WaitingList, Utilities]
2673+
2674+
def initialize
2675+
@queue = Queue.new # Refers to Utilities::Queue
2676+
end
2677+
end
2678+
end
2679+
```
2680+
26292681
* <a name="modules-vs-classes"></a>
26302682
Prefer modules to classes with only class methods. Classes should be used
26312683
only when it makes sense to create instances out of them.
@@ -3655,8 +3707,12 @@ resource cleanup when possible.
36553707
# bad
36563708
name = "Bozhidar"
36573709

3710+
name = 'De\'Andre'
3711+
36583712
# good
36593713
name = 'Bozhidar'
3714+
3715+
name = "De'Andre"
36603716
```
36613717

36623718
* **(Option B)** Prefer double-quotes unless your string literal
@@ -3666,8 +3722,12 @@ resource cleanup when possible.
36663722
# bad
36673723
name = 'Bozhidar'
36683724

3725+
sarcasm = "I \"like\" it."
3726+
36693727
# good
36703728
name = "Bozhidar"
3729+
3730+
sarcasm = 'I "like" it.'
36713731
```
36723732

36733733
The string literals in this guide are aligned with the first style.
@@ -3796,28 +3856,57 @@ resource cleanup when possible.
37963856

37973857
```ruby
37983858
# bad - using Powerpack String#strip_margin
3799-
code = <<-END.strip_margin('|')
3859+
code = <<-RUBY.strip_margin('|')
38003860
|def test
38013861
| some_method
38023862
| other_method
38033863
|end
3804-
END
3864+
RUBY
38053865

38063866
# also bad
3807-
code = <<-END
3867+
code = <<-RUBY
38083868
def test
38093869
some_method
38103870
other_method
38113871
end
3812-
END
3872+
RUBY
38133873

38143874
# good
3815-
code = <<~END
3875+
code = <<~RUBY
38163876
def test
38173877
some_method
38183878
other_method
38193879
end
3880+
RUBY
3881+
```
3882+
3883+
* <a name="heredoc-delimiters"></a>
3884+
Use descriptive delimiters for heredocs. Delimiters add valuable information
3885+
about the heredoc content, and as an added bonus some editors can highlight
3886+
code within heredocs if the correct delimiter is used.
3887+
<sup>[[link](#heredoc-delimiters)]</sup>
3888+
3889+
```ruby
3890+
# bad
3891+
code = <<~END
3892+
def foo
3893+
bar
3894+
end
38203895
END
3896+
3897+
# good
3898+
code = <<~RUBY
3899+
def foo
3900+
bar
3901+
end
3902+
RUBY
3903+
3904+
# good
3905+
code = <<~SUMMARY
3906+
An imposing black structure provides a connection between the past and
3907+
the future in this enigmatic adaptation of a short story by revered
3908+
sci-fi author Arthur C. Clarke.
3909+
SUMMARY
38213910
```
38223911

38233912
## Date & Time
@@ -4134,7 +4223,7 @@ resource cleanup when possible.
41344223

41354224
```ruby
41364225
# bad
4137-
def method_missing?(meth, *params, &block)
4226+
def method_missing(meth, *params, &block)
41384227
if /^find_by_(?<prop>.*)/ =~ meth
41394228
# ... lots of code to do a find_by
41404229
else
@@ -4143,7 +4232,7 @@ resource cleanup when possible.
41434232
end
41444233

41454234
# good
4146-
def method_missing?(meth, *params, &block)
4235+
def method_missing(meth, *params, &block)
41474236
if /^find_by_(?<prop>.*)/ =~ meth
41484237
find_by(prop, *params, &block)
41494238
else

0 commit comments

Comments
 (0)