From: "bkuhlmann (Brooke Kuhlmann)" Date: 2022-03-18T18:12:22+00:00 Subject: [ruby-core:107984] [Ruby master Feature#18648] ruby2_keywords and ... name arguments with impossible names Issue #18648 has been updated by bkuhlmann (Brooke Kuhlmann). Hey Aaron, in regards to `*`, `**`, and `&`, those are passthrough parameters (or bare parameters as I like to call them). For comparison: ``` ruby # Bare Parameters def demo(*, **, &) = super method(:demo).parameters # => [[:rest], [:keyrest], [:block, :&]] # Named Parameters def demo(*one, **two, &three) = super method(:demo).parameters # => [[:rest, :one], [:keyrest, :two], [:block, :three]] ``` > Why does only block get the faux name? One of the uses cases is so that you can pass the anonymous block up to the parent (if you were using inheritance): ``` ruby Parent = Class.new { def call(&block) = block.call } Child = Class.new(Parent) { def call(&) = super(&) } Child.new.call { "Hi" } # => "Hi" ``` This is syntactic sugar for not having to name your block if you don't need to. Support for this was added in [Ruby 3.1.0](https://rubyreferences.github.io/rubychanges/3.1.html#anonymous-block-argument) as is known as an anonymous block argument. ���� In case it helps, you can also use my [Marameters](https://www.alchemists.io/projects/marameters) gem to debug all of this further. This gem provides a nice API for accessing all of a method's parameters with minimal effort. ---------------------------------------- Feature #18648: ruby2_keywords and ... name arguments with impossible names https://bugs.ruby-lang.org/issues/18648#change-96936 * Author: aaronjensen (Aaron Jensen) * Status: Feedback * Priority: Normal ---------------------------------------- While investigating a break in a library using reflection, I realized that when ... is used or ruby2_keywords is used that Ruby will name arguments with their symbol, rather than leaving them unnamed. This test demonstrates the issue: https://github.com/ruby/ruby/blob/97426e15d721119738a548ecfa7232b1d027cd34/test/ruby/test_method.rb#L35 https://github.com/ruby/ruby/blob/97426e15d721119738a548ecfa7232b1d027cd34/test/ruby/test_method.rb#L586 I do not understand how `:*`, `:**`, and `:&` are meant to be considered valid parameter names. I assume the reason is so that they do not conflict with something a person could write but that they can still be referenced in Ruby to facilitate delegation but I just wanted to report that it caused a problem downstream. It's also curious that: ``` def foo(*, **, &) end ``` Gives these parameter: `[[:rest], [:keyrest], [:block, :&]]` Why does only `block` get the faux name? Is it because that's how yield works so there needs to be a way to reference it in Ruby? -- https://bugs.ruby-lang.org/ Unsubscribe: