ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: daniel@dan42.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:96585] [Ruby master Feature#16456] Ruby 2.7 argument delegation (...) should be its own kind of parameter in Method#parameters
Date: Sun, 29 Dec 2019 22:54:09 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-83552.20191229225409.952950d37ed5e875@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16456.20191227004215@ruby-lang.org

Issue #16456 has been updated by Dan0042 (Daniel DeLorme).


In the future it will be possible to combine `...` with other arguments. So if we think about what `parameters` would return in cases like these...

```ruby
method(def foo(a, *args, ...); end).parameters
#1=> [[:req, :a], [:rest, :args], [:delegate]]
#2=> [[:req, :a], [:rest, :args], [:keyrest], [:block]]
#3=> [[:req, :a], [:rest, :args], [:rest], [:keyrest], [:block]]

method(def foo(a, **kw, ...); end).parameters
#1=> [[:req, :a], [:keyrest, :kw], [:delegate]]
#2=> [[:req, :a], [:keyrest, :kw], [:rest], [:block]]
#3=> [[:req, :a], [:keyrest, :kw], [:rest], [:keyrest], [:block]]
```

I see the point of wanting to know if the method signature includes `...` or not, but I don't think I like the idea of having a `:delegate` that can mean different things.

What about this?
`[[:rest, :"..."], [:keyrest, :"..."], [:block, :"..."]]`

----------------------------------------
Feature #16456: Ruby 2.7 argument delegation (...) should be its own kind of parameter in Method#parameters
https://bugs.ruby-lang.org/issues/16456#change-83552

* Author: aaronc81 (Aaron Christiansen)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
A method defined with `...` as its parameter list is equivalent to one defined with `*args, &blk`, according to `Method#parameters`.

```ruby
def foo(...); end
p method(:foo).parameters
# => [[:rest, :*], [:block, :&]]
```

Even in Ruby 2.7, `...` and `*args, &blk` are not *quite* equivalent as the latter may produce a warning where the former does not. In Ruby 3.0 and beyond, `...` and `*args, &blk` will have a substantial semantic difference. Due to this, I don't consider the current behaviour of `Method#parameters` particularly ideal when dealing with methods using this new syntax.

If the goal of `...` is to be a "delegate everything" operator, even when parameter passing is changed like in Ruby 3.0, I would propose that `Method#parameters` considers it a unique type of parameter. For example:

```ruby
def foo(...); end
p method(:foo).parameters
# => [[:delegate, :"..."]]
```



-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2019-12-29 22:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-16456.20191227004215@ruby-lang.org>
2019-12-27  0:42 ` [ruby-core:96508] [Ruby master Feature#16456] Ruby 2.7 argument delegation (...) should be its own kind of parameter in Method#parameters aaronc20000
2019-12-27 11:29 ` [ruby-core:96511] " eregontp
2019-12-27 11:37 ` [ruby-core:96513] " zverok.offline
2019-12-27 17:35 ` [ruby-core:96517] " aaronc20000
2019-12-29 22:54 ` daniel [this message]
2019-12-31 17:30 ` [ruby-core:96608] " aaronc20000

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-83552.20191229225409.952950d37ed5e875@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).