The splat operator in Ruby, Groovy and Perl allows
you to switch between parameters and arrays:
it splits a list in a series of parameters,
or collects a series of parameters to fill an array.
The split mode turns an array into multiple-arguments:
>> duck, cow, pig = *["quack","mooh","oing"] => ["quack","mooh","oing"]
The collect mode turns multiple-arguments in an array:
>> *farm = duck, cow, pig => ["quack","mooh","oing"]
The splat operator can be used in a case statement :
WILD = ['lion','gnu'] TAME = ['cat','cow'] case animal when *WILD "Run" when *TAME "Catch" end
And it can be used to convert a hash into an array:
>> a = *{:a=>1,:b=>2}
=> [[:a,1],[:b,2]]
>> Hash[*a.flatten]
=> {:a=>1,:b=>2}
[...] * marks a pointer to a variable, while & is used to get the address of a variable. In Ruby, the splat operator * turns a list of arguments in an array, and the ampersand & marks a reference to a block which [...]