Quantcast
Channel: Ruby Issue Tracking System: shevegen (Robert A. Heiler)
Viewing all articles
Browse latest Browse all 100

Ruby master - Feature #16460: External names for keyword parameters in method definitions

$
0
0

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). :-)


Viewing all articles
Browse latest Browse all 100

Trending Articles