From: Le Wang (nospam) Date: 2002-01-01T09:43:40+09:00 Subject: [ruby-talk:29918] Re: && vs. and On Mon, 31 Dec 2001 12:39:15 GMT, David Alan Black wrote: >Hello -- > >On Mon, 31 Dec 2001, Le Wang wrote: > >> Hi all, >> >> In "Programming Ruby", it was explained that the only difference >> between '&&' and 'and' is precedence, the same seems to be implied in >> the 1.4 Reference Manual. >> >> >> true and puts 'test' >> true && puts 'test' >> >> >> Why doesn't the second statement work? > > >I believe it's parsed as: > > (true && puts) 'test' That explains it. I never took precedence that way. This leads to a design question. Since '&&' is a keyboard that performs boolean logic tests, should it not have lower precedence than all method calls? On top of this, '&&' is not a valid method name, so why is it parsed this way? > >so the bare string 'test' at the end of the line causes a parse error. > >Try: > > true && puts('test') > >(Hmmm... Playing around with this I'm mildly surprised that "true && >nil" is nil, rather than false.) > > >David