Double Splat
The Double Splat (**
) operator is used to expand a hash into keyword arguments in a method call.
Not quite what you're looking for? See the Arbitrary Keyword Arguments page or the Asterisk page for other ways that the asterisk symbol is used.
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)