From: "David A. Black" Date: 2008-02-05T06:28:56+09:00 Subject: Re: Expanding arrays in method calls - why the restriction? Hi -- On Tue, 5 Feb 2008, Phlip wrote: > mathew wrote: > >> system('du', *opts, '/tmp') >> >> which seems to me like a reasonable thing to want to do. > > system('du', *[opts + '/tmp']) > > In Ruby, never underestimate the power of the splat operator. > >> Is there some technical reason why the * parameter has to be the last one >> in the argument list, given that the array must be of finite size anyway, >> and presumably it gets expanded out in the process so that the receiver >> doesn't know an array was involved? > > I can't think of a reason either - the splat does evaluate before the method > call. Maybe it's just symmetry with the internal argument splat, which must > cohabit with default values and &block, so it must come relatively last. That's changed in 1.9. The starred one will get whatever's in the middle after the required args have been eaten up at the left and right ends: irb(main):006:0> def m(a,b,*c,d); p a,b,c,d; end => nil irb(main):007:0> m(1,2,3,4,5) 1 2 [3, 4] 5 And in general, you can now (1.9) unarray in the middle: irb(main):008:0> a = [1,2,3] => [1, 2, 3] irb(main):009:0> [1,2,*a,4] => [1, 2, 1, 2, 3, 4] David -- Training for 2008! Ruby on Rails training by David A. Black/Ruby Power and Light, LLC: * Intro to Rails, New York, NY, February 4-7 2008 * Advancing With Rails, New York, NY, February 11-14 2008 Hosted by Exceed Education. See http://www.rubypal.com for details!