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


> I am not sure how allowing parameters to Symbol#to_proc and Method#to_pro=
c would make:
> =

> ary.map(:dig.to_proc(:id))
> =

> possible as Array#map does not take an argument. What do you want it to r=
eturn?

to_proc on symbols creates a proc that receives an object and call the meth=
od with name equal to the symbol. The idea is to extend it so it can not on=
ly call the method on the object, but also to set the parameters to be used=
 in the call.

So,

`:dig.to_proc(:id)[ary]` would be the same as `ary.dig(:id)`.

Currently the Symbol to Proc feature is limited to methods that doesn't rec=
eive arguments... But I think that allowing this will open the doors to man=
y possibilities.

The use case for the map was one example only.

Unless there is some

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

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