Project

General

Profile

Actions

Feature #16456

closed

Ruby 2.7 argument delegation (...) should be its own kind of parameter in Method#parameters

Added by aaronc81 (Aaron Christiansen) over 2 years ago. Updated 7 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
[ruby-core:96508]

Description

A method defined with ... as its parameter list is equivalent to one defined with *args, &blk, according to Method#parameters.

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:

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

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #18011: `Method#parameters` is incorrect for forwarded argumentsClosedActions
Actions

Also available in: Atom PDF