From: Josh Cheek Date: 2012-01-31T16:22:31+09:00 Subject: Re: Multiple assignment in conditional --0016e6de00ec5bf06804b7cdd337 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Jan 31, 2012 at 12:46 AM, Gavin Sinclair wrote: > I find this a strange Ruby error. > > foo = [1,2] > > # The following is fine. > if (a = foo) > puts a > end > > # The following causes a SyntaxError: multiple assignment in conditional. > if (a, b = foo) > puts a > end > > > Why would that be a syntax error? Surely the grammar is > > if EXPR > ... > > and (a, b = foo) is an expression, isn't it? > > Just curious, though my curiosity was prompted by a failing piece of real > code. > > Gavin > What did you expect your real code to do? It seems to me that it should raise an error unless it's an array of size 2, and if it is, then it should return an array of size two, making the conditional necessarily true. So I don't know what you were expecting to happen. --0016e6de00ec5bf06804b7cdd337--