What does **options mean (two asterisk in argument list)?

Hi,

I guess it’s more of a Ruby than a Shrine question, but I’ve never seen this pattern in any other gem:

E.g. from https://shrinerb.com/docs/plugins/remote_url:

plugin :remote_url, downloader: -> (url, **options) { 

What does **options mean? Is there a name for **<something>? Unfortunately, questions regarding symbols/operators are hard to google.

Thanks

In ruby, putting two asterisks before a variable means “treat the following as a hash”. Similarly, using one asterisk means “treat the following as an array”.

In a method signature, it means “expand the hash you’ve been given into individual argument pairs”, which is a subtle refinement of this idea.

Walter

Could you share the link to some documentation?

With the answer provided by @walterdavis, I was able to figure it out:

  • **<something> is called a “Double Splat” in Ruby
  • Basically, def foo(url, **options) is quite similar to def foo(url, options={})
  • some more details can be found here

This explains it very well: https://stackoverflow.com/a/18289216/4880924