From: Rick DeNatale Date: 2009-12-02T00:26:34+09:00 Subject: Re: Splat array with 1 value in Ruby 1.9 vs Ruby 1.8 On Tue, Dec 1, 2009 at 12:53 AM, Raul Parolari wrote: > [ Sorry for the horrible indentation. I repeat the text renouncing to > align the expressions ] > > In porting some automation code from 1.8.7 to 1.9.1, I find that in ruby > 1.8 the following worked (real code is unpacking binary strings and > assigning variables, but I simplify for clarity): > >  var1  = *[ val1 ]   # => var1 = val1 > >  var1, var2, varn = *[ val1, val2, valn ] > > (I know that the splat is not necessary in the second case, but this > allowed the code to be generated in the same way, regardless of array > size). > > With Ruby 1.9.1, instead, this happens: > >   var1  = *[ val1 ]   # => var1 = [ val1 ]  (!) > >   var1, var2, varn = *[ val1, val2, valn ] > > Of course, this can be handled by generating code that checks the array > size. But I am curious on this behavior of splat when the array contains > one element (I read about the features of splat in 1.9, but they seem to > have nothing to do with this). Does anyone know if it is a bug or > intentional? Not sure exactly what you mean by generating the code, but could you use var1 = val1 and var1, var2, varn = val1, val2, valn -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale