From: "Wesley J. Landaker" Date: 2002-11-20T05:28:44+09:00 Subject: Re: difference between 'and' and '&&' Apparently, Volkmann, Mark recently wrote: > I thought the only difference between these was precedence, but I'm > seeing another difference. > > a = 'test' > b = nil > haveBoth = a and b > # haveBoth is now equal to 'test' > > haveBoth = a && b > # haveBoth is now equal to nil > > Is this the expected behavior? > > What I want to do is verify that two strings are not nil. > It looks like I have to use "&&" instead of "and" to do that. This is still the precedence difference: 'and' is lower than '=': Add some parenthesis and you get what you want: irb(main):001:0> a = 'test' "test" irb(main):002:0> b = nil nil irb(main):003:0> haveBoth = a and b nil irb(main):004:0> haveBoth "test" irb(main):005:0> haveBoth = (a and b) nil irb(main):006:0> haveBoth nil