Issue #16667 has been updated by shevegen (Robert A. Heiler).


I think this or something similar was suggested in the past, even aside from
the two linked in proposals. So this may even be older than 5 years. :)

I do not remember what the conclusion was in all these proposals (and perha=
ps
I misremember, but I think it was suggested even before those ~5 years, per=
haps
in another context).

As for the particular last syntax, I think this is quite inelegant:

    ary.map(&(:dig, :id))

Ruby users may feel that both :dig and :id have the same "importance",
since they are symbols, but if I understood it correctly then your
example would imply that dig refers to a method-name, and id refers
to an argument; and to me, if this is the case, this looks ... strange.
But I understand that this was just an example.

I also admit that I often prefer oldschool ruby, so I am biased. :)

Edit: Actually zverok suggested something similar. I believe we should be v=
ery
cautious about whether it is needed/necessary. When a feature is added, obv=
iously
people will use it, so all trade-offs should be considered (pro or con).

sawa wrote:

> or how it would be superior to writing like:

     ary.map { _1.dig(:id) }

Yes, this may be an additional question. But I think _1 _2 and so forth are
more useful when there are more parameters. I found that I actually only
use _1 _2 for quick debugging/writing, and replace it with the "real", long=
er
name lateron anyway.

----------------------------------------
Feature #16667: Allow parameters to Symbol#to_proc and Method#to_proc
https://bugs.ruby-lang.org/issues/16667#change-84444

* Author: jgomo3 (Jes=FAs G=F3mez)
* Status: Open
* Priority: Normal
----------------------------------------
Allow parameters to Symbol#to_proc and Method#to_proc

So we can say:

``` ruby
ary.map(:dig.to_proc(:id))
```


Instead of

``` ruby
ary.map { |e| e.dig(:id) }
```


Oppening the posibilities to refine the `&` operator in the future, for som=
ething like:


``` ruby
ary.map(&(:dig, :id))
```

Related:

* https://bugs.ruby-lang.org/issues/11161
* https://bugs.ruby-lang.org/issues/16435



-- =

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

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