Non-symbol kwargs #1609
Closed
sampersand
started this conversation in
Ideas
Replies: 1 comment
-
Moved to an issue, #1645 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
While working on
Kernel#system
, I came across a limitation of RBS: it only lets you specify symbol keyword arguments, and not any other type.Normal keyword arguments in Ruby are passed via
key: value
, such asgets(chomp: true)
. However, this syntax is actually sugar forgets(:chomp => true)
, and Ruby is capable of accepting other values for keys.Take this contrived example:
Or this slightly-less-contrived example:
There's no real way to typecheck this currently in RBS, as RBS only supports symbols for hash keys. It does have a
**rest
parameter, but that expects symbols as hash keys as well.I propose we add two new pieces of syntax to function declarations:
<literal> => <type>
, such asdef add_one: (0 => Integer)
.**<type> => <type>
, such asdef add_exponentiated_numbers: (**Integer => Integer)
.Notably, the
**
variant isn't equivalent (nor replaces) the current**<type> <variable>
syntax. For example, a simplifiedKernel#system
(which can take integers for hash keys, which correspond to hash descriptors) could be defined as:Beta Was this translation helpful? Give feedback.
All reactions