← Back to Ruby Operators

Double Splat

The Double Splat (**) operator is used to expand a hash into keyword arguments in a method call.

Here is an example of using double splat:

def execute_command(subcommand:, dir:, **other_options)
  set_directory(dir)

  # Here we double splat `other_options`
  execute_subcommand(subcommand, **other_options)
end

options_from_cli = {
  subcommand: 'migrate',
  dir: '/var/www/my_app',
  verbose: true
}

# Here is where we double splat `options_from_cli`
execute_command(**options_from_cli)

References