Issue #16460 has been updated by shevegen (Robert A. Heiler).


> A suggested syntax might be

     def name(external_name internal_name:)

Isn't this syntax already reserved/used for keyword arguments?

> Here is an example from Crystal (which has syntax very similar to Ruby)

matz knows crystal; he even donated a seizable sum to crystal way before that
donation-webpage + "hall of fame" for crystal existed. :-)

Many ruby folks also use crystal; in many ways crystal is like the closest
"brother" language to ruby. Though it is not quite ruby and neither is 
ruby crystal; IMO the type system is indeed the biggest difference and
makes for another language "feel" (but that is my opinion; I still think
it's great that crystal exists; I even once suggested to bridge the gap
between ruby code and crystal code, so we could write ruby, and have 
crystal code autogenerated from that. ;-))

> It would be especially helpful in Ruby as the language lacks a destructuring syntax
> for hashes/keyword args. 

I think pattern matching allows for destructuring? Not sure if I am right here, or
whether I have missed something, but the examples I could see were a lot about
destructuring hashes, like:

    case JSON.parse(json, symbolize_names: true)
    in {name: "Alice", children: [{name: "Bob", age: age}]}
      p age #=> 2

But it may be that I misunderstood you, or you had another intention/goal.

By the way, different languages use different syntaxes/patterns; it's not often
easy or possible or wanted to translate 1:1. But I don't want to sound
discouraging  either - just be prepared to update/modify the suggestion. What
helps the most is to focus on clear use cases; the ruby core team often 
recommends to have a clear use described case. Don't worry that this is your
first suggestion, everyone has to start at some point in time to contribute
to (if wanted). :-)

----------------------------------------
Feature #16460: External names for keyword parameters in method definitions
https://bugs.ruby-lang.org/issues/16460#change-83465

* 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: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>