On Tue, Jan 31, 2012 at 6:22 PM, Josh Cheek <josh.cheek / gmail.com> wrote:

>> # The following causes a SyntaxError: multiple assignment in conditional=
.
>> if (a, b =3D foo)
>> =A0puts a
>> end

> 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

Nope.  It can return anything at all and Ruby will deal with it.
Parallel assignment is (thankfully) flexible.

def foo; 1; end
a, b =3D foo            # returns 1; a =3D=3D 1, b =3D=3D nil

def bar; [1,2,3,4,5]; end
a, b =3D bar            # returns [1,2,3,4,5]; a =3D=3D 1, b =3D=3D 2

> and if it is, then it should
> return an array of size two, making the conditional necessarily true.

Nope.  The conditional can be false.

def foo; nil; end
a, b =3D foo            # returns nil; a =3D=3D nil, b =3D=3D nil

> So I don't know what you were expecting to happen.

def foo; nil; end

if (a, b =3D foo)
  puts "outcome 1"
else
  puts "outcome 2"   # I was expecting this.
end

Of course I don't have a function that returns nil unconditionally!
Just showing the structure.