From: jgomo3@...
Date: 2020-03-02T20:14:31+00:00
Subject: [ruby-core:97329] [Ruby master Feature#16667] Allow parameters to Symbol#to_proc and Method#to_proc

Issue #16667 has been updated by jgomo3 (Jes�s G�mez).


> I am not sure how allowing parameters to Symbol#to_proc and Method#to_proc would make:
> 
> ary.map(:dig.to_proc(:id))
> 
> possible as Array#map does not take an argument. What do you want it to return?

to_proc on symbols creates a proc that receives an object and call the method with name equal to the symbol. The idea is to extend it so it can not only 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 receive arguments... But I think that allowing this will open the doors to many 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�s G�mez)
* 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 something 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=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>