|
|
|
|
|
by thowaway91234
941 days ago
|
|
As a lifelong rubyist, this is definitely what I would say "useless". Maybe it's just because I've been stuck in Ruby 2.6 ~~hell~~ land for so long but I remember seeing a colleagues leetcode challenge for a job interview that used Ruby 3.1 and he used a bunch of these new syntax sugars and I was really rubbed the wrong way by them. Code the omits arguments is neither more readable (what exactly is getting passed around here?) or maintable (what happens when you have some condition that may apply to one of the arguments, then you just need to unwrap all the "nice" things and do it more traditionally). The elipsis ... especially rubs me the wrong way because multiple periods either .. or ... denotes range types, but now we have a special case where ... is something completely different. Bah humbug. They seem nice in clean blog scenarios with trivial examples, but in my experience they are not conducive to writing readable and maintable code. Thankfully I can just disable their use in my projects (for the most part) with rubocop. All the hip young kids can write their magic code, I'll stick to more straightforward constructs that anyone can figure out. |
|
If you have a wrapper for an API (say, that does some logging or whatever), you can use `…` to forward arguments, maintenance free.
Perhaps the wrapped function started out with no arg, but then added one. You never took/forwarded a `*vargs` array, so now you have to manually update that.
Then perhaps some other function started taking a block. Now you need to add `&block` and forward it.
So `…` is a maintenance-free way to forward arguments to functions that are free to change.