On Thu, Feb 2, 2012 at 3:56 AM, botp <botpena / gmail.com> wrote:
> On Thu, Feb 2, 2012 at 4:15 AM, Joel VanderWerf
> <joelvanderwerf / gmail.com> wrote:
>> You can trick ruby:
>>
>> def foo; nil; end
>>
>> if (_ =3D (a, b =3D foo))
>>
>> =A0puts "outcome 1"
>> else
>> =A0puts "outcome 2"
>> end
>>
>> So, the question is parsing, not semantics.
>
>
> indeed. ruby just checks the last assignment.
>
>> if (x,y=3D(a, b =3D 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=3Dfoo) 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.

08:45:50 ~$ allruby x.rb
CYGWIN_NT-5.1 padrklemme2 1.7.9(0.237/5/3) 2011-03-29 10:10 i686 Cygwin
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]
[nil]
"true"
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
ruby 1.9.3p0 (2011-10-30) [i386-cygwin]
nil
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
jruby 1.6.3 (ruby-1.8.7-p330) (2011-07-07 965162f) (Java HotSpot(TM)
Client VM 1.7.0_02) [Windows XP-x86-java]
[nil]
"true"
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
jruby 1.6.3 (ruby-1.9.2-p136) (2011-07-07 965162f) (Java HotSpot(TM)
Client VM 1.7.0_02) [Windows XP-x86-java]
[nil]
"true"
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
08:47:11 ~$ cat -n x.rb
     1
     2  def foo;nil end
     3
     4  x =3D (a,b=3Dfoo)
     5  p x
     6
     7  if (x =3D (a,b=3Dfoo))
     8    p "true"
     9  end
08:47:15 ~$

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/