From: Raul Parolari Date: 2009-12-02T00:59:04+09:00 Subject: Re: Splat array with 1 value in Ruby 1.9 vs Ruby 1.8 Rick Denatale wrote: > On Tue, Dec 1, 2009 at 12:53 AM, Raul Parolari > wrote: >> >> 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 As I said at the beginning of the post, the code is unpacking binary strings, which generates an array (else of course I would have not added the array, just for the fun of having to remove it). For example: x, y = "\x23\x00\x61".unpack('Cn') # => [35, 97]; so: x = 35; y = 97 Now, when there is just one variable to extract, we get (as expected): z="\x00\x61".unpack('n') # z = [97] To get the scalar values in both cases, in 1.8.7 a splat operator in front of the right value expression (placed by the code generator) does the job; in 1.9.1, it does not. The solution is simple, but I was not asking for "a solution". In other words, I was just pointing out this difference of behavior: a = *[ 3 ] # => a =3 with Ruby 1.8.7 a = *[ 3 ] # => a = [ 3 ] with Ruby 1.9.1 I think that this is a bug in Ruby 1.9. Raul Parolari x = -- Posted via http://www.ruby-forum.com/.