Feature #16404
closedAdd Proc#ruby2_keywords
Description
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:
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
Updated by matz (Yukihiro Matsumoto) about 5 years ago
It is ugly, and I personally don't want to add it to the language. But I have to admit it solves the real-world issues in some cases. So I accept. This might be removed sometime in Ruby3.x (after proper deprecation process).
Matz.
Updated by jeremyevans0 (Jeremy Evans) about 5 years ago
- Status changed from Open to Closed
Committed at f45c0dc23980d7fd8167d290ea7c354cf2cdb500.