On Tue, Jan 31, 2012 at 12:46 AM, Gavin Sinclair <gsinclair / gmail.com>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.