这是splat操作符 http://theplana.wordpress.com/2007/03/03/ruby-idioms-the-splat-operator/。您经常会看到它用于将数组拆分为函数的参数。
def my_function(param1, param2, param3)
param1 + param2 + param3
end
my_values = [2, 3, 5]
my_function(*my_values) # returns 10
更常见的是它用于接受任意数量的参数
def my_other_function(to_add, *other_args)
other_args.map { |arg| arg + to_add }
end
my_other_function(1, 6, 7, 8) # returns [7, 8, 9]
它也适用于多重赋值(尽管这两个语句都可以在没有 splat 的情况下工作):
first, second, third = *my_values
*my_new_array = 7, 11, 13
对于您的示例,这两个是等效的:
p *1..10
p 1, 2, 3, 4, 5, 6, 7, 8, 9, 10