Ruby Single and Double Splat Operators

Single Splat operator as an argument in the function's definition

Double Splat operator in a function

Double Splat operator when calling a function

  • The Hash must have precisely the same keys.
  • The Hash must have the keys as symbols, not strings. Read this issue if you are curious to see why it doesn't use Strings.

Double Splat operator as an argument in the function's definition:

  • The Double Splat is optional. You don't need to pass a value to the function.
  • The Double Splat cannot have a default value, while the simple Hash can. The default value of the Double Splat is implicitly the empty Hash ({} ).
  • If there are default values in positional arguments, the results could differ. See the following example:

Combining different types of arguments

Be careful!

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store