From: zverok.offline@... Date: 2019-12-28T08:44:54+00:00 Subject: [ruby-core:96540] [Ruby master Feature#16460] External names for keyword parameters in method definitions Issue #16460 has been updated by zverok (Victor Shepelev). Jut two points to add: * the feature like this _might_ be useful for arguments named as Ruby keywords/core methods (e.g. things like `run :some_task, if: :condition?`, `convert(value, raise: false)`, `schedule(:worker, in: 5.minutes)` etc.), as @nobu mentions, currently the only way to get those variables in method body is `local_variable_get` (and with `raise` example, even it will not help, the problem is trickier) * the `name alt_name:` syntax look completely "alien" to me (in context of "what exists in Ruby"), I'd say, considering new pattern-matching examples, something with `=>` _might_ work (while still looking ugly): ```ruby def run(task, if: => condition) p condition end # with default value, looks a bit less cringy: def convert(value, raise: false => should_raise) if should_raise # ... end ---------------------------------------- Feature #16460: External names for keyword parameters in method definitions https://bugs.ruby-lang.org/issues/16460#change-83468 * Author: harrisonb (Harrison Bachrach) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Hello! This is my first time filing an issue and I was unable to find anything similar. I apologize if one already exists. In other languages (such as JavaScript, Swift, and Crystal), it is possible to have two names for a given keyword argument: one that is used in method invocation, and one used in the method definition. Here is an example from Crystal (which has syntax very similar to Ruby): ```crystal def increment(value, by amount) value + amount end increment(value: 5, by: 10) ``` This helps create more readable method invocations and definitions. It would be especially helpful in Ruby as the language lacks a destructuring syntax for hashes/keyword args. This is unlike JavaScript, where you can do something like ```javascript const { nameOfOneProperty: newNameForTheProperty, nameOfAnotherProperty: newNameForTheOtherProperty } = foo; ``` I'm thinking that such a change would pair nicely with the new 3.0 keyword argument changes. A suggested syntax might be ```ruby def name(external_name internal_name:) # ... end -- https://bugs.ruby-lang.org/ Unsubscribe: