From: Robert Klemme Date: 2012-02-02T19:35:08+09:00 Subject: Re: Multiple assignment in conditional On Thu, Feb 2, 2012 at 10:03 AM, botp wrote: > On Thu, Feb 2, 2012 at 4:57 PM, botp wrote: >> On Thu, Feb 2, 2012 at 3:47 PM, Robert Klemme >> wrote: >>> On Thu, Feb 2, 2012 at 3:56 AM, botp wrote: >>>> indeed. ruby just checks the last assignment. >>>> >>>>> if (x,y=(a, b = foo)) >>>>> p 1 >>>>> end >>>> SyntaxError: (irb):17: multiple assignment in conditional >>>> >>>> but i do not know why it has to do that checking. too much work. and >>>> could probably slow down ruby. >>> >>> Probably because (a,b=foo) in all but the latest version always yields >>> an Array which is true hence does not make sense as a condition.  You >>> could write if (true) as well. >> >> ah, portability/compatibility. i guess we're stucked then :) >> thanks Robert. >> best regards -botp > > ok, i'll take it back, since, > if only the latest version makes sense, then wouldn't that mean it's > not really being used in the earlier versions,  and therefore,  it > *is* safe to implement it currently, ie remove the checking? I think so. But that still does not make it a brilliant idiom in my eyes. Granted, the example Gavin presented looks pretty reasonable. However, I haven't missed this feature in all those years so I am a tad uncertain how common or uncommon that is. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/