From: Karl Allmark Date: 2006-01-12T22:06:56+09:00 Subject: Re: Newbie question about multiple assignments >> 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 >>> >> >> Keep in mind, that >> >> a, b = c, d >> >> is just shorthand for >> >> a, b = [c, d] >> >> So, your expression >> >> a, b = b, a = a, b >> >> gets parsed as >> >> a, b = [b, a = a, b] >> >> and thus produces the observed behaviour. >> >> HTH, >> >> Michael >> >> > > >That doesn't seem to explain the return value [2, 1, 2] of the expression. > >David Vallner Hi List Just getting up to speed with ruby myself, try reading Davids explaination as: a, b = [b,(a = a), b] Karl Allmark