From: "jeremyevans0 (Jeremy Evans)" Date: 2021-12-14T15:29:10+00:00 Subject: [ruby-core:106656] [Ruby master Feature#18351] Support anonymous rest and keyword rest argument forwarding Issue #18351 has been updated by jeremyevans0 (Jeremy Evans). Eregon (Benoit Daloze) wrote in #note-5: > jeremyevans0 (Jeremy Evans) wrote in #note-4: > > Can anyone show a problem with having Method#parameters for `foo(...)` and `def foo(*, **, &)` return the same result? > > I think there may be value to distinguish `...` and `*, **, &`. > That's pretty much the subject of #16456. > For instance a method taking `...` seems to very very likely use delegation, while a method using `*, **, &` not necessarily (e.g., it could pass positional to one methods, kwargs to another and block to a third method). The purpose of Method#parameters is to show what arguments are accepted by the method, not how the arguments are handled. > Another issue is if one wants to detect `...` they would actually need to check `parameters == [[:rest, :*], [:keyrest, :**], [:block, :&]]` and not e.g. just `parameters.include?([:rest, :*])` which would also be true for `def m(*)`. Since `...` and `*, **, &` accept the same arguments, from Method#parameters perspective, treating them the same seems reasonable. > Also, this changes the parameters for `def m(*)` from `[[:rest]]` to `[[:rest, :*]]`, I think that's bad as some code might rely on that. You are correct that callers might need to make changes, but they should be used to that. Callers already need to handle `[:rest, :*]` if they are handling `...`. They needed new handling in 2.7 for `...` and `**nil`, and will need new handling in 3.1 for the change in `...` (as 3.1 includes :keyrest for `...`). Basically, the Method#parameters return value has been changing regularly, so this change seems like it should be acceptable. That being said, it's possible to use a different value for the internal local variable for `*` and `**`, and recognize it in Method#parameters, to keep the output the same. ---------------------------------------- Feature #18351: Support anonymous rest and keyword rest argument forwarding https://bugs.ruby-lang.org/issues/18351#change-95328 * Author: jeremyevans0 (Jeremy Evans) * Status: Open * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- I would like to add support for the following syntax: ```ruby def foo(*) bar(*) end def baz(**) quux(**) end ``` This is a natural addition after the introduction of anonymous block forwarding. Anonymous rest and keyword rest arguments were already supported in method parameters, this just allows them to be used as arguments to other methods. The same advantages of anonymous block forwarding apply to rest and keyword rest argument forwarding. I've submitted a pull request implementing this syntax: https://github.com/ruby/ruby/pull/5148 -- https://bugs.ruby-lang.org/ Unsubscribe: