Issue #16667 has been updated by jgomo3 (Jes=FAs G=F3mez).


sawa (Tsuyoshi Sawada) wrote in #note-4:
> I already know that. That does not make `ary.map(:dig.to_proc(:id))` work=
. You seemed to have missed my point.

Ok, it would be actually `ary.map(&:dig.to_proc(:id))`.

But that is not the important thing.

The core is just the ability to make "to_proc" useful for symbols of method=
s that require an argument.

Currently, there is no use of `dig.to_proc`, but if we allow the parameter,=
 then all those symbols will benefit better from `to_proc`.

Here is a proof of concept:

```ruby
class Symbol
  def to_proc(extra=3Dnil)
    ->(obj) { obj.public_send(self, *extra) }
  end
end

dig_id =3D :dig.to_proc(:id)

h =3D {id: 1, v: 10}
dig_id[h] # 1

ary =3D [{id: 1, v: 10}, {id: 2, v:34}]
ary.map(&dig_id) # [1, 2]
```

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

* 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>