From: David Vallner Date: 2006-01-12T20:06:18+09:00 Subject: Re: Newbie question about multiple assignments To your why, another why: why do you need to use multiple parallel assignments in one statement? That said, parallel assignments are somewhat known to be a rather messy bit of syntax I'm apparently not as savvy with as I thought, since I can't make heads or tails of what is really happening. My personal tip woukd be that the assignments are associative right-to-left, and only the leftmost assignment is evaluated as a parallel one. What probably happens is broken down into simpler statements: a = a, b # a == [1, 2] a, b = b, *a # a ==2, b==1 where the return value of the expression is the rvalue. So the end values are what you expect, just the return value of the expression isn't. Hint: it's easy to avoid obscure syntax, so do that if possible. Noone really admires godawful one-liners from hell in code he expects to understand a week after writing it, even if there is a certain charm to getting things done with them ;) Also, parallel assignment syntax is undergoing certain subtle, but significant changes that seem to resolve some of the ambiguity - you might want to look on one of the webpages that summarize changes in Ruby 1.9. David Vallner On Thu, 12 Jan 2006 11:24:45 +0100, Alex wrote: > > irb(main):091:0> a=1 > => 1 > irb(main):092:0> b=2 > => 2 > irb(main):093:0> a,b=b,a > => [2, 1] > irb(main):094:0> a=1 > => 1 > irb(main):095:0> b=2 > => 2 > irb(main):096:0> a, b = b, a = a, b > => [2, 1, 2] <-- Why? > > What is the order for the assignments >