-
-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Named Arguments #625
Named Arguments #625
Conversation
Co-authored-by: jansul <jon@sul.ly>
.parameters | ||
.index { |param| param.label == argument.name.try(&.value) } | ||
|
||
raise CallNotFoundArgument, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise CallNotFoundArgument, { | |
raise ArgumentNameMismatch, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree with change, it's not a mismatch (although it could be) but a not found parameter.
If we really need to change this, then It could be CallArgumentNameMismatch
.
parameters.map(&.to_pretty.as(String)) | ||
parameters.map do |param| | ||
pretty = | ||
param.to_pretty.as(String) | ||
|
||
if param.label | ||
"#{param.label}: #{pretty}" | ||
else | ||
pretty | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd refactor this into Record#to_pretty(named_arguments: true)
.
[skip ci] Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
[skip ci] Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 🤩
As a side note: I'd use Calls with named arguments or Named arguments in calls wording rather than Labeled calls, which IMO is a bit abstract. |
This PR implements the ability to call functions with an alternative syntax using the names of the arguments.
The only rule as of now is that there can't be normal arguments and labelled arguments in a call.