Feature #21973
openSmile argument
Description
Ruby makes us smile. So I want Ruby to smile too, and that is why I would like to propose this feature.
The smile argument makes Ruby smile by allowing a method call to end its argument list with :).
smile_method(arg, :)
This syntax implicitly supplies keyword arguments by matching the names of local variables in the current scope with the names of the method’s keyword parameters.
For example, if a method has the following signature:
some_method(arg, smile:, hugging:)
then these two calls would be equivalent:
arg = "hello"
smile = "smile"
hugging = "hugging"
some_method(arg, smile:, hugging:)
arg = "hello"
smile = "smile"
hugging = "hugging"
some_method(arg, :)
The motivation behind this feature is the assumption that names used in a method signature are often also used at the call site.
For instance, if a library method defines keyword arguments like (from:, to:), I expect that code using that method would often have local variables named from and to holding the actual values before passing them along.
In real application development, when developers adopt a new library, they will usually look at the argument list of the method they want to call. If they intend to use that method as designed, it seems natural that they may also choose the same variable names as those in the method signature.
This idea was inspired by Scala’s implicit parameters. It is not exactly the same feature, but as a lazy person, I find the idea of context-driven currying quite appealing.
In any case, the real purpose is to make Ruby smile.
Happy Ruby! And happy April Fools' Day!
Files
