Tom Pollard
12/20/2006 3:54:00 AM
On Dec 19, 2006, at 9:58 PM, Luciano Ramalho wrote:
> On 12/19/06, Peter Szinek <peter@rubyrailways.com> wrote:
>> foo = false
>> bar = true
>>
>> baz = foo or bar
>>
>> baz ends up false (because = has greater priority than or)
>
> That sucks. Why would anyone want = to be evaluated before anything
> else?
The point is that 'or' and 'and' have /lower/ precedence than
anything else, so that they can be used to chain complete expressions
together. This is a Perl-ism, to my knowledge and a number of
common Perl idioms are based on this. (...like, 'open(my $handle,
$filename) or die'). I'm a nuby here, but I haven't seen the weak
'and' and 'or' used much in Ruby - at least, not in the same
circumstances where I'm used to seeing it in Perl code.
Cheers,
TomP