Ruby * operator before an array

Possible duplicate:
Understanding the ruby ​​symbol in ranges and arrays

can someone tell me what * is doing in the following code snippet?

line = "name=yabbi;language=ruby;" Hash[*line.split(/=|;/)] 

Thanks.

+6
source share
2 answers

* is the splat operator. It is used to split the array into a list of arguments.

line.split(/=|;/) returns an array. To create a hash, each element of the array must be passed as a separate parameter.

+6
source

This is a splat statement . Read about it. Often you see that it is used when you want to split the array into use as function parameters.

0
source

All Articles