You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 3.3.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,6 +65,48 @@ In Ruby 3.3, it will just warn to prepare for a change.
65
65
```
66
66
* **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.
67
67
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).
# 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
+
defm(*)
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
+
68
110
## Core classes and modules[](#core-classes-and-modules)
69
111
70
112
### `Kernel#lambda` raises when passed `Proc` instance[](#kernellambda-raises-when-passed-proc-instance)
Copy file name to clipboardExpand all lines: _src/3.3.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,6 +65,48 @@ In Ruby 3.3, it will just warn to prepare for a change.
65
65
```
66
66
* **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.
67
67
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).
# 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
+
defm(*)
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
+
68
110
## Core classes and modules
69
111
70
112
### `Kernel#lambda` raises when passed `Proc` instance
# Only accepts positional arguments and passes them further
361
361
def log(level, *) = logger.log(level, *)
362
362
363
363
# Only accepts anonymous keyword args and passes them further
364
364
def get(url, **) = send_request(:get, url, **)
365
365
```
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.
366
367
367
368
<!--
368
369
* [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.))
# Only accepts positional arguments and passes them further
361
361
def log(level, *) = logger.log(level, *)
362
362
363
363
# Only accepts anonymous keyword args and passes them further
364
364
def get(url, **) = send_request(:get, url, **)
365
365
```
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.
366
367
367
368
<!--
368
369
*<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