Jim Cochrane wrote:
> On 2008-04-20, Joel VanderWerf <vjoel / path.berkeley.edu> wrote:
>> Alex Shulgin wrote:
>>> Hi,
>>>
>>> Anyone aware of this bug?
>>>
>>> $ cat expr-bug.rb
>>> a = (2
>>>   + 2) / 2
>>> p a
>> AFAIK not a bug. It's because parens can contain two or more 
>> expressions, separated by either newlines or semicolons.
>>
>> x = 5
>>
>> a = (x+=1
>>       x + 2) / 2
>> p a # ==> 4
>>
>> #equiv to:
>> a = (x+=1; x + 2) / 2
>> p a # ==> 4
>>
>> (I'm not advocating either of the above forms, FWIW.)
>>
> 
> I was wondering what that had to do with:
> 
> a = (2
> + 2) / 2
> 
> until I realized (I think), after experimenting with irb that you are
> implying that the above is equivalent to:
> 
> a = (2;
> +2) / 2
> 
> which is the same as 'a = (+2) / 2' -> 'a = 2/2' -> a = 1
> 
> but:
> 
> a = (2 +
> 2) / 2
> 
> is the same as 'a = (2 + 2) / 2' -> 'a = 4 / 2'

Right. I should have said that the expression

   + 2

is treated as applying the unary operator #+ to the integer 2.

Be careful with irb... sometimes it's a little different from ruby.

-- 
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407