How do splat (*) and double splat (**) operators work in method arguments?
Last updated
In a definition,
*argsgathers positional arguments into an Array and**optsgathers keyword arguments into a Hash.At a call site they work in reverse:
*arrayexpands into positional args and**hashinto keyword args.Forward everything with
*args, **kwargs, &blockor...(Ruby 2.7+).
- https://docs.ruby-lang.org/en/3.0/syntax/methods_rdoc.html
- https://docs.ruby-lang.org/capi/en/master/d8/d6b/diagnostic_8c_source.html
- https://docs.ruby-lang.org/en/3.1/syntax/calling_methods_rdoc.html
- https://docs.ruby-lang.org/en/master/syntax/calling_methods_rdoc.html
- https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
- https://www.railscarma.com/blog/guide-to-the-ruby-splat-operator-single-and-double/
- https://medium.com/@kabirpathak99/ruby-splat-and-double-splat-operators-18ebb733eb4c
- https://dev.to/jasonfb/ruby-arguments-40m4