Project

General

Profile

Actions

Bug #20955

open

Subtle differences with Proc#parameters for anonymous parameters

Added by zverok (Victor Shepelev) 3 days ago. Updated 1 day ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.0dev (2024-12-15T13:36:38Z master 366fd9642f) +PRISM [x86_64-linux]
[ruby-core:120252]

Description

p proc { |x| }.parameters   #=> [[:opt, :x]]
p lambda { |x| }.parameters #=> [[:req, :x]]
p proc { _1 }.parameters    #=> [[:opt, :_1]]
p lambda { _1 }.parameters  #=> [[:req, :_1]]
p proc { it }.parameters    #=> [[:opt, nil]]
p lambda { it }.parameters  #=> [[:req]]

Note the last pair; here are two small confusing problems:

  1. For proc, unlike numbered parameters, the parameter name is nil (not it). This, though, can be justified to distinguish from proc { |it| } case
  2. But also, proc has this nil for a parameter name, while lambda has not.

I am not sure what the “most logical” thing to do here, but I believe that at least proc { it } and lambda { it } should be made consistent with each other.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0