Project

General

Profile

Actions

Feature #21813

closed

Add [:forward, :...] symbol tuple to indicate forwarding arguments when calling `Method#parameters`

Feature #21813: Add [:forward, :...] symbol tuple to indicate forwarding arguments when calling `Method#parameters`
1

Added by pabloh (Pablo Herrero) about 2 months ago. Updated 11 days ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:124385]

Description

When accessing Method#parameters for a method using forwarding parameters, an unexpected behavior arises:

def foo(*, **, &)
  args = method(__method__).parameters.map(&:last).join(',')

  binding.eval "print(#{args})" # Works fine
end

foo(1,2,3,4, a: 23) # => 1234{a: 23}

def bar(...)
  args = method(__method__).parameters.map(&:last).join(',') 

  binding.eval "print(#{args})" # Fails!
end

bar(1,2,3,3, a: 23) # SyntaxError

It's very strange that you can't access the parameters, on eval, using the symbols provided at Method#parameters.

Adding [:forward, :...] or [:forwarding, :...] for those cases feels simply natural.

Updated by pabloh (Pablo Herrero) about 2 months ago Actions #1

  • Description updated (diff)

Updated by pabloh (Pablo Herrero) about 2 months ago Actions #2

  • Description updated (diff)

Updated by pabloh (Pablo Herrero) about 2 months ago Actions #3

  • Description updated (diff)

Updated by pabloh (Pablo Herrero) about 2 months ago Actions #4

  • Description updated (diff)

Updated by nobu (Nobuyoshi Nakada) about 1 month ago Actions #5 [ruby-core:124499]

foo(a: 1) doesn't print what you expect, I guess.

Updated by pabloh (Pablo Herrero) about 1 month ago · Edited Actions #6 [ruby-core:124524]

@nobu (Nobuyoshi Nakada) Perhaps I came up with a contrived example, but I wanted to point out that there is a lack of symmetry when it comes to ...
As of right now, there is no way to know from the Method reflection API alone whether a method is using argument forwarding. You’d have to use Method#source_location and then parse the source file somehow.

EDIT: I updated the example for better clarity, but the main point remains the same: the lack of an introspection API for argument forwarding.

Updated by pabloh (Pablo Herrero) about 1 month ago Actions #7

  • Description updated (diff)

Updated by matz (Yukihiro Matsumoto) 11 days ago Actions #8 [ruby-core:124784]

  • Status changed from Open to Rejected

I failed to persuade me. I admit there's a lack of symmetry, but I don't think it's not worth the potential performance burden.

Matz.

Actions

Also available in: PDF Atom