Skip to content

Commit 95077d1

Browse files
committed
A 3.3 feature that was merged in the last moment
1 parent b6dee34 commit 95077d1

File tree

9 files changed

+98
-10
lines changed

9 files changed

+98
-10
lines changed

2.4.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ description: Ruby 2.4 full and annotated changelog
1616
-->
1717

1818
* **Released at:** Dec 25, 2016 (<a class="github" href="https://github.com/ruby/ruby/blob/trunk/doc/NEWS-2.4.0">NEWS</a> file)
19-
* **Status (as of Dec 21, 2023):** EOL, latest is 2.4.10
19+
* **Status (as of Dec 25, 2023):** EOL, latest is 2.4.10
2020
* **This document first published:** Oct 14, 2019
21-
* **Last change to this document:** Dec 21, 2023
21+
* **Last change to this document:** Dec 25, 2023
2222

2323
## Highlights[](#highlights)
2424

2.7.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ description: Ruby 2.7 full and annotated changelog
88
# Ruby 2.7
99

1010
* **Released at:** Dec 25, 2019 (<a class="github" href="https://github.com/ruby/ruby/blob/ruby_2_7/NEWS">NEWS</a> file)
11-
* **Status (as of Dec 21, 2023):** 2.7.8 is EOL
11+
* **Status (as of Dec 25, 2023):** 2.7.8 is EOL
1212
* **This document first published:** Dec 27, 2019
13-
* **Last change to this document:** Dec 21, 2023
13+
* **Last change to this document:** Dec 25, 2023
1414

1515
<!-- TODO: all links to docs should be replaced with /2.7.0/ suffix instead of /master/ when 2.7.0 would be published -->
1616

3.0.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ description: Ruby 3.0 full and annotated changelog
88
# Ruby 3.0
99

1010
* **Released at:** Dec 25, 2020 (<a class="github" href="https://github.com/ruby/ruby/blob/ruby_3_0/NEWS.md">NEWS.md</a> file)
11-
* **Status (as of Dec 23, 2023):** 3.0.6 is security maintenance (will EOL soon!)
11+
* **Status (as of Dec 25, 2023):** 3.0.6 is security maintenance (will EOL soon!)
1212
* **This document first published:** Dec 25, 2020
13-
* **Last change to this document:** Dec 23, 2023
13+
* **Last change to this document:** Dec 25, 2023
1414

1515
## Highlights[](#highlights)
1616

3.2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ description: Ruby 3.2 full and annotated changelog
88
# Ruby 3.2
99

1010
* **Released at:** Dec 25, 2022 (<a class="github" href="https://github.com/ruby/ruby/blob/ruby_3_2/NEWS.md">NEWS.md</a> file)
11-
* **Status (as of Dec 24, 2023):** 3.2.2 is current _stable_
11+
* **Status (as of Dec 25, 2023):** 3.2.2 is current _stable_
1212
* **This document first published:** Feb 4, 2022
13-
* **Last change to this document:** Dec 24, 2023
13+
* **Last change to this document:** Dec 25, 2023
1414

1515
<!--
1616
* **Reason:**

3.3.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,48 @@ In Ruby 3.3, it will just warn to prepare for a change.
6565
```
6666
* **Notes:** The new feature isn't expected to conflict with RSpec's [`it`](https://rspec.info/documentation/3.12/rspec-core/RSpec/Core/ExampleGroup.html#it-class_method), as calling that without any block attached, or at least a description for the future example, is useless.
6767
68+
### Anonymous parameters forwarding inside blocks are disallowed[](#anonymous-parameters-forwarding-inside-blocks-are-disallowed)
69+
70+
Now anonymous parameters forwarding inside a block raise error.
71+
72+
* **Reason:** Blocks didn't support anonymous parameters _forwarding_, yet they supported anonymous parameters _declaration_, and it was a confusing situation (when something that looked like block forwarding its parameters, actually forwarded parameters of the method containing the block).
73+
* **Discussion:** <a class="tracker feature" href="https://bugs.ruby-lang.org/issues/19370">Feature #19370</a>
74+
* **Code:**
75+
```ruby
76+
def m(*)
77+
# ..some other code using anonymous params...
78+
79+
[1, 2, 3].each { |*| p(*) }
80+
end
81+
m('test')
82+
83+
# Ruby 3.2:
84+
# The block above looks like it would forward its arguments to p
85+
# (so it would print 1, 2, 3); but actually anonymous params of the _method_
86+
# are forwarded, so it actually prints:
87+
# "test"
88+
# "test"
89+
# "test"
90+
91+
# Ruby 3.3:
92+
# anonymous rest parameter is also used within block (SyntaxError)
93+
# (raised during parsing the file)
94+
95+
# No error is raised if there's no perceived conflict of anonymous
96+
# params:
97+
def m(*)
98+
# ..some other code using anonymous params...
99+
100+
[1, 2, 3].each { |i| p(*) } # no question what `*` refers to
101+
end
102+
m('test')
103+
# Ruby 3.3:
104+
# "test"
105+
# "test"
106+
# "test"
107+
```
108+
* **Notes:** There is a [question](https://bugs.ruby-lang.org/issues/19370#note-9) whether disallowing block parameters forwarding is the best way to solve the confusion; alternative solution would be just to support forwarding inside the block properly. I hope the discussion to continue during 3.4 development.
109+
68110
## Core classes and modules[](#core-classes-and-modules)
69111

70112
### `Kernel#lambda` raises when passed `Proc` instance[](#kernellambda-raises-when-passed-proc-instance)

_data/book.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ chapters:
119119
- title: Standalone <code>it</code> in blocks will become anonymous argument in
120120
Ruby 3.4
121121
path: "/3.3.html#standalone-it-in-blocks-will-become-anonymous-argument-in-ruby-34"
122+
- title: Anonymous parameters forwarding inside blocks are disallowed
123+
path: "/3.3.html#anonymous-parameters-forwarding-inside-blocks-are-disallowed"
122124
- title: Core classes and modules
123125
path: "/3.3.html#core-classes-and-modules"
124126
children:

_src/3.3.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,48 @@ In Ruby 3.3, it will just warn to prepare for a change.
6565
```
6666
* **Notes:** The new feature isn't expected to conflict with RSpec's [`it`](https://rspec.info/documentation/3.12/rspec-core/RSpec/Core/ExampleGroup.html#it-class_method), as calling that without any block attached, or at least a description for the future example, is useless.
6767
68+
### Anonymous parameters forwarding inside blocks are disallowed
69+
70+
Now anonymous parameters forwarding inside a block raise error.
71+
72+
* **Reason:** Blocks didn't support anonymous parameters _forwarding_, yet they supported anonymous parameters _declaration_, and it was a confusing situation (when something that looked like block forwarding its parameters, actually forwarded parameters of the method containing the block).
73+
* **Discussion:** [Feature #19370](https://bugs.ruby-lang.org/issues/19370)
74+
* **Code:**
75+
```ruby
76+
def m(*)
77+
# ..some other code using anonymous params...
78+
79+
[1, 2, 3].each { |*| p(*) }
80+
end
81+
m('test')
82+
83+
# Ruby 3.2:
84+
# The block above looks like it would forward its arguments to p
85+
# (so it would print 1, 2, 3); but actually anonymous params of the _method_
86+
# are forwarded, so it actually prints:
87+
# "test"
88+
# "test"
89+
# "test"
90+
91+
# Ruby 3.3:
92+
# anonymous rest parameter is also used within block (SyntaxError)
93+
# (raised during parsing the file)
94+
95+
# No error is raised if there's no perceived conflict of anonymous
96+
# params:
97+
def m(*)
98+
# ..some other code using anonymous params...
99+
100+
[1, 2, 3].each { |i| p(*) } # no question what `*` refers to
101+
end
102+
m('test')
103+
# Ruby 3.3:
104+
# "test"
105+
# "test"
106+
# "test"
107+
```
108+
* **Notes:** There is a [question](https://bugs.ruby-lang.org/issues/19370#note-9) whether disallowing block parameters forwarding is the best way to solve the confusion; alternative solution would be just to support forwarding inside the block properly. I hope the discussion to continue during 3.4 development.
109+
68110
## Core classes and modules
69111

70112
### `Kernel#lambda` raises when passed `Proc` instance

_src/evolution.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,15 @@ This section lists changes in how methods are defined and invoked, as well as ne
355355
File.open(filename, &)
356356
end
357357
```
358-
* [3.2](3.2.md#anonymous-arguments-passing-improvements) Anonymous keyword and positional arguments ([Methods: Array/Hash Argument](https://docs.ruby-lang.org/en/3.2/syntax/methods_rdoc.html#label-Array-2FHash+Argument)):
358+
* [3.2](3.2.md#anonymous-arguments-passing-improvements) Anonymous keyword and positional arguments forwarding ([Methods: Array/Hash Argument](https://docs.ruby-lang.org/en/3.2/syntax/methods_rdoc.html#label-Array-2FHash+Argument)):
359359
```ruby
360360
# Only accepts positional arguments and passes them further
361361
def log(level, *) = logger.log(level, *)
362362
363363
# Only accepts anonymous keyword args and passes them further
364364
def get(url, **) = send_request(:get, url, **)
365365
```
366+
* [3.3](3.3.md#anonymous-parameters-forwarding-inside-blocks-are-disallowed) Anonymous parameters forwarding inside blocks are disallowed, when the block also has anonymous parameters.
366367

367368
<!--
368369
* [3.1](3.1.md#inside-endless-method-definitions-method-calls-without-parenthesis-are-allowed) Inside "endless" method definitions, method calls without parenthesis are allowed (— ([doc/syntax/methods.rdoc](https://docs.ruby-lang.org/en/3.1/syntax/methods_rdoc.html) doesn't mention new or old behavior.))

evolution.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,15 @@ This section lists changes in how methods are defined and invoked, as well as ne
355355
File.open(filename, &)
356356
end
357357
```
358-
* <span class="ruby-version">[3.2](3.2.md#anonymous-arguments-passing-improvements)</span> Anonymous keyword and positional arguments (<a class="ruby-doc" href="https://docs.ruby-lang.org/en/3.2/syntax/methods_rdoc.html#label-Array-2FHash+Argument">Methods: Array/Hash Argument</a>):
358+
* <span class="ruby-version">[3.2](3.2.md#anonymous-arguments-passing-improvements)</span> Anonymous keyword and positional arguments forwarding (<a class="ruby-doc" href="https://docs.ruby-lang.org/en/3.2/syntax/methods_rdoc.html#label-Array-2FHash+Argument">Methods: Array/Hash Argument</a>):
359359
```ruby
360360
# Only accepts positional arguments and passes them further
361361
def log(level, *) = logger.log(level, *)
362362
363363
# Only accepts anonymous keyword args and passes them further
364364
def get(url, **) = send_request(:get, url, **)
365365
```
366+
* <span class="ruby-version">[3.3](3.3.md#anonymous-parameters-forwarding-inside-blocks-are-disallowed)</span> Anonymous parameters forwarding inside blocks are disallowed, when the block also has anonymous parameters.
366367

367368
<!--
368369
* <span class="ruby-version">[3.1](3.1.md#inside-endless-method-definitions-method-calls-without-parenthesis-are-allowed)</span> Inside "endless" method definitions, method calls without parenthesis are allowed (— (<a class="ruby-doc" href="https://docs.ruby-lang.org/en/3.1/syntax/methods_rdoc.html"><code>doc/syntax/methods.rdoc</code></a> doesn't mention new or old behavior.))

0 commit comments

Comments
 (0)