Issue #15708 has been updated by Eregon (Benoit Daloze).


As I said in #15723,

I believe the `|x,|` behavior for `@1` can only be considered a bug.

It prevents `array_of_arrays.each { p @1 }` to work correctly.
Why would we want to prevent that and make this pattern not general, dangerous, inconsistent and unusable for nested arrays?
This doesn't make any sense to me.

How can this be intended?
It ignores elements and make one of the simplest use of `@1` wrong.

```ruby
array_of_arrays = [[1,2], [3,4]]
array_of_arrays.each { p @1 }
# => 1
# => 3
```

The same happens for every block with `@` which passed value happens to be an Array.

This kind of behavior is what I learned in programming languages classes as a design flaw,
because it cannot handle properly elements independent of their representation.

----------------------------------------
Bug #15708: Implicit numbered argument decomposes an array
https://bugs.ruby-lang.org/issues/15708#change-77544

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.7.0dev
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
In the following, `@1` refers to the entire item iterated:

```ruby
a = [1, 2, 3]
a.map{|x| x} # => [1, 2, 3]
a.map{@1} # => [1, 2, 3]
```

whereas in the following, `@1` refers to the first item achieved by decomposing the item iterated, behaving the same as `x` given by `|(x)|` rather than by `|x|`:

```ruby
a = [[1], [2], [3]]
a.map{|x| x} # => [[1], [2], [3]]
a.map{|(x)| x} # => [1, 2, 3]
a.map{@1} # => [1, 2, 3]
```

Is this intended?



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>