News for hackers. Stuff that matters.
Re:Ruby 3.1.0 Preview 1 by lamontcg on Tuesday November 09, 2021 @01:32PM (#29165458)
Keyword args are real nice for maintaining API compatibility but they're commonly passed down through the call stack resulting in a lot of:

"foo(arg, my_keyword1: my_keyword1, my_keyword2: my_keyword2, my_keyword3: my_keyword3)"

that now becomes:

"foo(arg, my_keyword1:, my_keyword2:, my_keyword3:)"

that is just a bit less for your eyes to have to digest and parse, although i can see leaving the trailing colon off as being a common bug.

sometimes you can just double splat both the signature and the wrapped invocation, but if you need to peel off kwargs in the wrapper method then you're stuck passing them all back in, or else you fall back to pulling kwargs out of a hash (plus you lose some level of auto-documentation in the method signature that way).

it'd be kind of nice to have a literal which could be passed into the method invocation that would expand out to all the kwargs that were passed, while still being explicit in the definition.

There are no comments on this comment yet.