[ruby-core:96122] [Ruby master Feature#16404] Add Proc#ruby2_keywords
From:
merch-redmine@...
Date:
2019-12-05 19:20:29 UTC
List:
ruby-core #96122
Issue #16404 has been reported by jeremyevans0 (Jeremy Evans).
----------------------------------------
Feature #16404: Add Proc#ruby2_keywords
https://bugs.ruby-lang.org/issues/16404
* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
While the need is not as common as for methods, procs could benefit from supporting ruby2_keywords, and there are cases in Rails where keywords are passed through procs using a normal argument splat [1]. If we don't add this, such cases will require separate proc definitions depending on ruby version. With this, you only need to call `ruby2_keywords` on the proc if it is defined. Example:
```ruby
foo = ->(*args, &block){block.call(*args)}
foo.call(a: 1, &->(**x){x})
# warning: The last argument is used as the keyword parameter
# warning: for `call' defined here; maybe ** should be added to the call?
# => {:a=>1}
foo.ruby2_keywords
foo.call(a: 1, &->(**x){x})
# => {:a=>1}
```
I've added a pull request for this: https://github.com/ruby/ruby/pull/2728
[1] https://github.com/rails/rails/blob/34d66ca6bab109540299a7b30980627bea37e323/activemodel/lib/active_model/type/registry.rb#L12
--
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>