From: "Jesús Gabriel y Galán" Date: 2010-10-26T23:59:20+09:00 Subject: Re: Extraction of single subarrays from multidimensional array On Tue, Oct 26, 2010 at 4:05 PM, Maurizio Cirilli wrote: > Thanks a lot Robert for your clear explanation and help. > In order to fully understand the code you provided, could you > please to tell what is the role of the asterisk in the > statement: > > a, b, c = *ss > > I did not find (or probably I just missed) this operator in the Ruby > docs I have. It's usually called the splat operator, and its function in the above expression is to take the array elements one by one and use them in the parallel assigment, so that the first element is assigned to a, the second to b, the third to c, and any other is discarded. It's also used to collect the rest of the parameters in an assigment or in a method call: irb(main):001:0> ss = [1,2,3,4,5] => [1, 2, 3, 4, 5] irb(main):002:0> a,b,c = *ss => [1, 2, 3, 4, 5] irb(main):003:0> a => 1 irb(main):004:0> b => 2 irb(main):005:0> c => 3 irb(main):006:0> a,b,*c = *ss => [1, 2, 3, 4, 5] irb(main):007:0> a => 1 irb(main):008:0> b => 2 irb(main):009:0> c => [3, 4, 5] irb(main):010:0> def test a,b,*c irb(main):011:1> p [a,b,c] irb(main):012:1> end => nil irb(main):013:0> test 1,2,3,4,5,6 [1, 2, [3, 4, 5, 6]] Jesus.