[ruby-core:118250] [Ruby master Feature#20565] Relax formal argument at label

Issue #20565 has been reported by nobu (Nobuyoshi Nakada). ---------------------------------------- Feature #20565: Relax formal argument at label https://bugs.ruby-lang.org/issues/20565 * Author: nobu (Nobuyoshi Nakada) * Status: Open ---------------------------------------- Just a thought: if `def foo(if:)` is possible, shouldn't `def foo(C:)` and `def foo($g:)` also be possible...? -- https://bugs.ruby-lang.org/

Issue #20565 has been updated by Earlopain (A S). I knew you can use keywords as names here but am not quite sure about this. Positional arguments (against my expectations from keyword arguments) don't allow any of these three versions. Should they also work? I think it would be nice if they behave the same for keyword identifiers at least. While you are able to create local variables that look like keywords with `binding.local_variable_set`, the same is not true for identifiers that look like constants or globals.
wrong local variable name '$g' for #<Binding:0x00007cd6436e88e0> wrong local variable name 'C' for #<Binding:0x0000738701442b08>
---------------------------------------- Feature #20565: Relax formal argument at label https://bugs.ruby-lang.org/issues/20565#change-108748 * Author: nobu (Nobuyoshi Nakada) * Status: Open ---------------------------------------- Just a thought: if `def foo(if:)` is possible, shouldn't `def foo(C:)` and `def foo($g:)` also be possible...? -- https://bugs.ruby-lang.org/

Issue #20565 has been updated by Eregon (Benoit Daloze). I think it should remain forbidden, arguments must be local variables, but `C` and `$g` are not valid local variable names. ---------------------------------------- Feature #20565: Relax formal argument at label https://bugs.ruby-lang.org/issues/20565#change-108749 * Author: nobu (Nobuyoshi Nakada) * Status: Open ---------------------------------------- Just a thought: if `def foo(if:)` is possible, shouldn't `def foo(C:)` and `def foo($g:)` also be possible...? -- https://bugs.ruby-lang.org/

Issue #20565 has been updated by zverok (Victor Shepelev).
I knew you can use keywords as names here but am not quite sure about this. Positional arguments (against my expectations from keyword arguments) don't allow any of these three versions. Should they also work?
The reason why keywords can be used in names is expressiveness on the caller site (not relevant to positional argument), like ```ruby validate :something, if: :something_else association :name, class: "Blah" ``` It is inconvenient to fetch such argument values, but it allows to create very expressive APIs. The alternative would be to have—sometimes discussed—“renaming” declarations in signatures, something like ```ruby def validate(name, condition if: nil) ``` With argument named `if:` by the caller, but available as a local variable `condition` in the method body. ---------------------------------------- Feature #20565: Relax formal argument at label https://bugs.ruby-lang.org/issues/20565#change-108753 * Author: nobu (Nobuyoshi Nakada) * Status: Open ---------------------------------------- Just a thought: if `def foo(if:)` is possible, shouldn't `def foo(C:)` and `def foo($g:)` also be possible...? -- https://bugs.ruby-lang.org/
participants (4)
-
Earlopain (A S)
-
Eregon (Benoit Daloze)
-
nobu (Nobuyoshi Nakada)
-
zverok (Victor Shepelev)