From: "bkuhlmann (Brooke Kuhlmann) via ruby-core" Date: 2024-12-16T17:13:42+00:00 Subject: [ruby-core:120263] [Ruby master Bug#20955] Subtle differences with Proc#parameters for anonymous parameters Issue #20955 has been updated by bkuhlmann (Brooke Kuhlmann). @zverok Makes sense...but this behavior would be nice (again, thinking in terms of consistency): ``` ruby proc { |_1| }.parameters # _1 is reserved for numbered parameter (SyntaxError) proc { |it| }.parameters # it is a reserved block parameter (SyntaxError) ``` _I realize this would break backwards compatibility in terms of semantic versioning, though._ That said, I can provide an example of `it` -- as currently implemented in Ruby 3.4.0-rc1 -- that would cause issues with my [Marameters](https://alchemists.io/projects/marameters) gem. ������ Please note that the syntax I'm showing you is for the next _major_ release of the gem once Ruby 3.4.0 is released: ``` ruby parameters = proc { it }.parameters signature = Marameters.signature(parameters).to_s # " = nil" Demo = Module.new do module_eval <<~METHOD, __FILE__, __LINE__ + 1 def self.test(#{signature}) = "This is a demo." METHOD end Demo.test # syntax errors found (SyntaxError) # ��� This is because a method signature of `test( = nil)` is definitely not syntactically valid. ``` I can definitely fix my Marameters gem to account for this use case but would be nice to ensure `Method#parameters` _always_ answers an array than can immediately be used to _dynamically_ build a new method signature that is _syntactically correct_. ---------------------------------------- Bug #20955: Subtle differences with Proc#parameters for anonymous parameters https://bugs.ruby-lang.org/issues/20955#change-111030 * Author: zverok (Victor Shepelev) * Status: Open * ruby -v: ruby 3.4.0dev (2024-12-15T13:36:38Z master 366fd9642f) +PRISM [x86_64-linux] * Backport: 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED ---------------------------------------- ```ruby 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. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/