Skip to content

Commit 49ad36c

Browse files
committed
2.7.0preview2: Excessive indent for code blocks
fixup #2202
1 parent bfd46aa commit 49ad36c

File tree

2 files changed

+112
-112
lines changed

2 files changed

+112
-112
lines changed

en/news/_posts/2019-10-22-ruby-2-7-0-preview2-released.md

+56-56
Original file line numberDiff line numberDiff line change
@@ -60,76 +60,76 @@ deprecated, and conversion will be removed in Ruby 3. [[Feature #14183]](https:
6060
splat operator to avoid the warning and ensure correct behavior in
6161
Ruby 3.
6262

63-
```ruby
64-
def foo(key: 42); end; foo({key: 42}) # warned
65-
def foo(**kw); end; foo({key: 42}) # warned
66-
def foo(key: 42); end; foo(**{key: 42}) # OK
67-
def foo(**kw); end; foo(**{key: 42}) # OK
68-
```
63+
```ruby
64+
def foo(key: 42); end; foo({key: 42}) # warned
65+
def foo(**kw); end; foo({key: 42}) # warned
66+
def foo(key: 42); end; foo(**{key: 42}) # OK
67+
def foo(**kw); end; foo(**{key: 42}) # OK
68+
```
6969
7070
* When a method call passes keywords to a method that accepts keywords,
7171
but it does not pass enough required positional arguments, the
7272
keywords are treated as a final required positional argument, and a
7373
warning is emitted. Pass the argument as a hash instead of keywords
7474
to avoid the warning and ensure correct behavior in Ruby 3.
7575
76-
```ruby
77-
def foo(h, **kw); end; foo(key: 42) # warned
78-
def foo(h, key: 42); end; foo(key: 42) # warned
79-
def foo(h, **kw); end; foo({key: 42}) # OK
80-
def foo(h, key: 42); end; foo({key: 42}) # OK
81-
```
76+
```ruby
77+
def foo(h, **kw); end; foo(key: 42) # warned
78+
def foo(h, key: 42); end; foo(key: 42) # warned
79+
def foo(h, **kw); end; foo({key: 42}) # OK
80+
def foo(h, key: 42); end; foo({key: 42}) # OK
81+
```
8282
8383
* When a method accepts specific keywords but not a keyword splat, and
8484
a hash or keywords splat is passed to the method that includes both
8585
Symbol and non-Symbol keys, the hash will continue to be split, and
8686
a warning will be emitted. You will need to update the calling code
8787
to pass separate hashes to ensure correct behavior in Ruby 3.
8888
89-
```ruby
90-
def foo(h={}, key: 42); end; foo("key" => 43, key: 42) # warned
91-
def foo(h={}, key: 42); end; foo({"key" => 43, key: 42}) # warned
92-
def foo(h={}, key: 42); end; foo({"key" => 43}, key: 42) # OK
93-
```
89+
```ruby
90+
def foo(h={}, key: 42); end; foo("key" => 43, key: 42) # warned
91+
def foo(h={}, key: 42); end; foo({"key" => 43, key: 42}) # warned
92+
def foo(h={}, key: 42); end; foo({"key" => 43}, key: 42) # OK
93+
```
9494
9595
* If a method does not accept keywords, and is called with keywords,
9696
the keywords are still treated as a positional hash, with no warning.
9797
This behavior will continue to work in Ruby 3.
9898
99-
```ruby
100-
def foo(opt={}); end; foo( key: 42 ) # OK
101-
```
99+
```ruby
100+
def foo(opt={}); end; foo( key: 42 ) # OK
101+
```
102102
103103
* Non-symbols are allowed as a keyword argument keys if method accepts
104104
arbitrary keywords. [[Feature #14183]](https://bugs.ruby-lang.org/issues/14183)
105105
106-
```ruby
107-
def foo(**kw); p kw; end; foo("str" => 1) #=> {"str"=>1}
108-
```
106+
```ruby
107+
def foo(**kw); p kw; end; foo("str" => 1) #=> {"str"=>1}
108+
```
109109
110110
* <code>**nil</code> is allowed in method definitions to explicitly mark
111111
that the method accepts no keywords. Calling such a method with keywords
112112
will result in an ArgumentError. [[Feature #14183]](https://bugs.ruby-lang.org/issues/14183)
113113
114-
```ruby
115-
def foo(h, **nil); end; foo(key: 1) # ArgumentError
116-
def foo(h, **nil); end; foo(**{key: 1}) # ArgumentError
117-
def foo(h, **nil); end; foo("str" => 1) # ArgumentError
118-
def foo(h, **nil); end; foo({key: 1}) # OK
119-
def foo(h, **nil); end; foo({"str" => 1}) # OK
120-
```
114+
```ruby
115+
def foo(h, **nil); end; foo(key: 1) # ArgumentError
116+
def foo(h, **nil); end; foo(**{key: 1}) # ArgumentError
117+
def foo(h, **nil); end; foo("str" => 1) # ArgumentError
118+
def foo(h, **nil); end; foo({key: 1}) # OK
119+
def foo(h, **nil); end; foo({"str" => 1}) # OK
120+
```
121121
122122
* Passing an empty keyword splat to a method that does not accept keywords
123123
no longer passes an empty hash, unless the empty hash is necessary for
124124
a required parameter, in which case a warning will be emitted. Remove
125125
the double splat to continue passing a positional hash. [[Feature #14183]](https://bugs.ruby-lang.org/issues/14183)
126126
127-
```ruby
128-
h = {}; def foo(*a) a end; foo(**h) # []
129-
h = {}; def foo(a) a end; foo(**h) # {} and warning
130-
h = {}; def foo(*a) a end; foo(h) # [{}]
131-
h = {}; def foo(a) a end; foo(h) # {}
132-
```
127+
```ruby
128+
h = {}; def foo(*a) a end; foo(**h) # []
129+
h = {}; def foo(a) a end; foo(**h) # {} and warning
130+
h = {}; def foo(*a) a end; foo(h) # [{}]
131+
h = {}; def foo(a) a end; foo(h) # {}
132+
```
133133
134134
## Other Notable New Features
135135
@@ -140,36 +140,36 @@ deprecated, and conversion will be removed in Ruby 3. [[Feature #14183]](https:
140140
* A beginless range is experimentally introduced. It might not be as useful
141141
as an endless range, but would be good for DSL purpose. [[Feature #14799]](https://bugs.ruby-lang.org/issues/14799)
142142
143-
```ruby
144-
ary[..3] # identical to ary[0..3]
145-
rel.where(sales: ..100)
146-
```
143+
```ruby
144+
ary[..3] # identical to ary[0..3]
145+
rel.where(sales: ..100)
146+
```
147147
148148
* `Enumerable#tally` is added. It counts the occurrence of each element.
149149

150-
```ruby
151-
["a", "b", "c", "b"].tally
152-
#=> {"a"=>1, "b"=>2, "c"=>1}
153-
```
150+
```ruby
151+
["a", "b", "c", "b"].tally
152+
#=> {"a"=>1, "b"=>2, "c"=>1}
153+
```
154154

155155
* Calling a private method on `self` is now allowed. [[Feature #11297]](https://bugs.ruby-lang.org/issues/11297) [[Feature #16123]](https://bugs.ruby-lang.org/issues/16123)
156156

157-
```ruby
158-
def foo
159-
end
160-
private :foo
161-
self.foo
162-
```
157+
```ruby
158+
def foo
159+
end
160+
private :foo
161+
self.foo
162+
```
163163

164164
* `Enumerator::Lazy#eager` is added. It generates a non-lazy enumerator
165165
from a lazy enumerator. [Feature #15901]
166166

167-
```ruby
168-
a = %w(foo bar baz)
169-
e = a.lazy.map {|x| x.upcase }.map {|x| x + "!" }.eager
170-
p e.class #=> Enumerator
171-
p e.map {|x| x + "?" } #=> ["FOO!?", "BAR!?", "BAZ!?"]
172-
```
167+
```ruby
168+
a = %w(foo bar baz)
169+
e = a.lazy.map {|x| x.upcase }.map {|x| x + "!" }.eager
170+
p e.class #=> Enumerator
171+
p e.map {|x| x + "?" } #=> ["FOO!?", "BAR!?", "BAZ!?"]
172+
```
173173

174174
## Performance improvements
175175

ja/news/_posts/2019-10-22-ruby-2-7-0-preview2-released.md

+56-56
Original file line numberDiff line numberDiff line change
@@ -51,60 +51,60 @@ Ruby に添付されている REPL (Read-Eval-Print-Loop) である `irb` で、
5151

5252
* メソッド呼び出しにおいて最後の引数としてハッシュオブジェクトを渡し、他にキーワード引数を渡さず、かつ、呼ばれたメソッドがキーワード引数を受け取るとき、警告が表示されます。キーワード引数として扱いたい場合は、明示的にdouble splat演算子(`**`)を足すことで警告を回避できます。このように書けばRuby 3でも同じ意味で動きます。
5353

54-
```ruby
55-
def foo(key: 42); end; foo({key: 42}) # warned
56-
def foo(**kw); end; foo({key: 42}) # warned
57-
def foo(key: 42); end; foo(**{key: 42}) # OK
58-
def foo(**kw); end; foo(**{key: 42}) # OK
59-
```
54+
```ruby
55+
def foo(key: 42); end; foo({key: 42}) # warned
56+
def foo(**kw); end; foo({key: 42}) # warned
57+
def foo(key: 42); end; foo(**{key: 42}) # OK
58+
def foo(**kw); end; foo(**{key: 42}) # OK
59+
```
6060
6161
* キーワード引数を受け取るメソッドにキーワード引数を渡すが、必須引数が不足している場合に、キーワード引数は最後の必須引数として解釈され、警告が表示されます。警告を回避するには、キーワードではなく明示的にハッシュとして渡してください。このように書けばRuby 3でも同じ意味で動きます。
6262
63-
```ruby
64-
def foo(h, **kw); end; foo(key: 42) # warned
65-
def foo(h, key: 42); end; foo(key: 42) # warned
66-
def foo(h, **kw); end; foo({key: 42}) # OK
67-
def foo(h, key: 42); end; foo({key: 42}) # OK
68-
```
63+
```ruby
64+
def foo(h, **kw); end; foo(key: 42) # warned
65+
def foo(h, key: 42); end; foo(key: 42) # warned
66+
def foo(h, **kw); end; foo({key: 42}) # OK
67+
def foo(h, key: 42); end; foo({key: 42}) # OK
68+
```
6969
7070
* メソッドがキーワード引数を受け取るがdouble splat引数は受け取らず、かつ、メソッド呼び出しでSymbolと非Symbolの混ざったハッシュを渡す(もしくはハッシュをdouble splatでキーワードとして渡す)場合、ハッシュは分割され、警告が表示されます。Ruby 3でもハッシュの分割を続けたい場合は、呼び出し側で明示的に分けるようにしてください。
7171
72-
```ruby
73-
def foo(h={}, key: 42); end; foo("key" => 43, key: 42) # warned
74-
def foo(h={}, key: 42); end; foo({"key" => 43, key: 42}) # warned
75-
def foo(h={}, key: 42); end; foo({"key" => 43}, key: 42) # OK
76-
```
72+
```ruby
73+
def foo(h={}, key: 42); end; foo("key" => 43, key: 42) # warned
74+
def foo(h={}, key: 42); end; foo({"key" => 43, key: 42}) # warned
75+
def foo(h={}, key: 42); end; foo({"key" => 43}, key: 42) # OK
76+
```
7777
7878
* メソッドがキーワード引数を受け取らず、呼び出し側でキーワード引数を渡した場合、ハッシュの引数としてみなされる挙動は変わらず、警告も表示されません。Ruby 3でもこのコードは動き続ける予定です。
7979
80-
```ruby
81-
def foo(opt={}); end; foo( key: 42 ) # OK
82-
```
80+
```ruby
81+
def foo(opt={}); end; foo( key: 42 ) # OK
82+
```
8383
8484
* メソッドが任意のキーワードを受け取る場合、非Symbolがキーワード引数のキーとして許容されるようになります。[[Feature #14183]](https://bugs.ruby-lang.org/issues/14183)
8585
86-
```ruby
87-
def foo(**kw); p kw; end; foo("str" => 1) #=> {"str"=>1}
88-
```
86+
```ruby
87+
def foo(**kw); p kw; end; foo("str" => 1) #=> {"str"=>1}
88+
```
8989
9090
* メソッド定義で<code>**nil</code>と書くことで、このメソッドがキーワードを受け取らないことを明示できるようになりました。このようなメソッドをキーワード引数付きで呼び出すとArgumentErrorになります。[[Feature #14183]](https://bugs.ruby-lang.org/issues/14183)
9191
92-
```ruby
93-
def foo(h, **nil); end; foo(key: 1) # ArgumentError
94-
def foo(h, **nil); end; foo(**{key: 1}) # ArgumentError
95-
def foo(h, **nil); end; foo("str" => 1) # ArgumentError
96-
def foo(h, **nil); end; foo({key: 1}) # OK
97-
def foo(h, **nil); end; foo({"str" => 1}) # OK
98-
```
92+
```ruby
93+
def foo(h, **nil); end; foo(key: 1) # ArgumentError
94+
def foo(h, **nil); end; foo(**{key: 1}) # ArgumentError
95+
def foo(h, **nil); end; foo("str" => 1) # ArgumentError
96+
def foo(h, **nil); end; foo({key: 1}) # OK
97+
def foo(h, **nil); end; foo({"str" => 1}) # OK
98+
```
9999
100100
* キーワード引数を受け取らないメソッドに対して空のハッシュをdouble splatで渡すとき、空のハッシュが渡る挙動はなくなりました。ただし、必須引数が不足する場合は空のハッシュが渡され、警告が表示されます。ハッシュの引数として渡したい場合はdouble splatをつけないようにしてください。
101101
102-
```ruby
103-
h = {}; def foo(*a) a end; foo(**h) # []
104-
h = {}; def foo(a) a end; foo(**h) # {} and warning
105-
h = {}; def foo(*a) a end; foo(h) # [{}]
106-
h = {}; def foo(a) a end; foo(h) # {}
107-
```
102+
```ruby
103+
h = {}; def foo(*a) a end; foo(**h) # []
104+
h = {}; def foo(a) a end; foo(**h) # {} and warning
105+
h = {}; def foo(*a) a end; foo(h) # [{}]
106+
h = {}; def foo(a) a end; foo(h) # {}
107+
```
108108
109109
## 主要な新機能
110110
@@ -114,35 +114,35 @@ Ruby に添付されている REPL (Read-Eval-Print-Loop) である `irb` で、
114114
115115
* 開始値省略範囲式が試験的に導入されました。これは終了値省略範囲式ほど有用ではないと思われますが、しかし DSL のような目的には役立つかもしれません。 [[Feature #14799]](https://bugs.ruby-lang.org/issues/14799)
116116
117-
```ruby
118-
ary[..3] # identical to ary[0..3]
119-
rel.where(sales: ..100)
120-
```
117+
```ruby
118+
ary[..3] # identical to ary[0..3]
119+
rel.where(sales: ..100)
120+
```
121121
122122
* `Enumerable#tally` が追加されました。各要素の出現回数を数えます。
123123

124-
```ruby
125-
["a", "b", "c", "b"].tally
126-
#=> {"a"=>1, "b"=>2, "c"=>1}
127-
```
124+
```ruby
125+
["a", "b", "c", "b"].tally
126+
#=> {"a"=>1, "b"=>2, "c"=>1}
127+
```
128128

129129
* レシーバを`self`としてprivateメソッドを呼び出すことが許容されるようになりました。 [[Feature #11297]](https://bugs.ruby-lang.org/issues/11297) [[Feature #16123]](https://bugs.ruby-lang.org/issues/16123)
130130

131-
```ruby
132-
def foo
133-
end
134-
private :foo
135-
self.foo
136-
```
131+
```ruby
132+
def foo
133+
end
134+
private :foo
135+
self.foo
136+
```
137137

138138
* `Enumerator::Lazy#eager` が追加されました。lazyなEnumeratorを非lazyなEnumeratorに変換します。
139139

140-
```ruby
141-
a = %w(foo bar baz)
142-
e = a.lazy.map {|x| x.upcase }.map {|x| x + "!" }.eager
143-
p e.class #=> Enumerator
144-
p e.map {|x| x + "?" } #=> ["FOO!?", "BAR!?", "BAZ!?"]
145-
```
140+
```ruby
141+
a = %w(foo bar baz)
142+
e = a.lazy.map {|x| x.upcase }.map {|x| x + "!" }.eager
143+
p e.class #=> Enumerator
144+
p e.map {|x| x + "?" } #=> ["FOO!?", "BAR!?", "BAZ!?"]
145+
```
146146

147147
## パフォーマンスの改善
148148

0 commit comments

Comments
 (0)