On Saturday 07 June 2008 23:03:47 jzakiya wrote:
> On Jun 7, 11:35 pm, Rimantas Liubertas <riman... / gmail.com> wrote:

> > $ irb --simple-prompt>> n1, n2, n3, n4 = *[1, 2, 3, 4]

Probably easier to simply do

n1, n2, n3, n4 = 1, 2, 3, 4

But I'm not sure that's what you wanted.

> n1, n2, n3, n4 = 5

n1 = n2 = n3 = n4 = 5

This works because the result of the assignment is the value which was 
assigned. It's also not Ruby-specific. Probably even works in C.

> and  do +=, -=, *=, etc with the same value
> 
> n1, n2, n3, n4 += 5

This doesn't work because of the semantics of multiple assignment. See, your 
first example:

n1, n2, n3, n4 = nil

That doesn't work because there's anything magical about nil. It works because 
nil is the value when nothing is provided. It parses out to something like 
this:

n1, n2, n3, n4 = nil, nil, nil, nil

And you can see this effect, too:

n1, n2, n3, n4 = 5

n1 will be 5, but n2, n3, and n4 won't be.

Now, with your semantics of doing a += there, shouldn't it be more like:

n1, n2, n3, n4 += 1, 2, 3, 4

> instead of
> 
> n1 += 9; n2 += 9; n3 += 9; n4 += 9

Erm... I can't ever remember needing this. Not ever.

If you're trying to do it on an array, maybe something like:

0.upto(a.length-1) { |i| a[i] += 9 }

But unless I'm missing something -- and feel free to correct me with a real 
example -- what you're trying to do really suggests that you want to refactor 
your program a bit.