From: Raul Parolari Date: 2009-12-02T03:11:24+09:00 Subject: Re: Splat array with 1 value in Ruby 1.9 vs Ruby 1.8 Robert Klemme wrote: > On 12/01/2009 05:56 PM, Raul Parolari wrote: >>> >>> [456] >>> Kind regards >> 1.9 (else I don't understand fully what a splat operator is, and I'd >> like to know more). > > I know there have been some things changed with regard to how the splat > operator works, including more complex patterns: > > robert@fussel:~$ ruby1.9 -e 'def f(a,*b,c)p a,b,c end;f(1, 2, 3, 4)' > 1 > [2, 3] > 4 > > This did not work in 1.8: > ... > > The changes may make it necessary that 1.9 behaves the way you observed. > That's why I said I am not sure whether it is actually a bug. > Hmm.. the difference is: a) in 1.8 the splat operator could only be applied to the last left-value b) in 1.9 the splat operator can appear at any position in the list of left-values But the concept of the operation has remained identical: all extra rvalues are placed into an array Similarly, 1.9 adds more flexibility when the splat is done on an rvalue (multiple splats). But the concept is still the same (in this case, as Matz/Flanagan's book says "the array elements replace the array in the original rvalue"). That's the reason that I think the behavior of a = *[ 3 ] # => a = [ 3 ] is a bug; else, it would go against the definition just given (just because the array has 1 element). Just my opinion, of course. --- In any case, thanks again for the elegant solution to my code generation Raul Parolari -- Posted via http://www.ruby-forum.com/.