Ruby Double star (**)
def hello(a, *b, **c)
return a, b, c
end
a
is a regular parameter. *b
will take all the parameters passed after the first one and put them in an array. **c
will take any parameter given in the format key:
value at the end of the method call.
See the following examples:
One parameter
hello(1)
# => [1, [], {}]
More than one parameter
hello(1, 2, 3, 4)
# => [1, [2, 3, 4], {}]
More than one parameter + hash-style parameters
hello(1, 2, 3, 4, a: 1, b: 2)
# => [1, [2, 3, 4], {:a=>1, :b=>2}]