Posts Tagged and
and vs && in ruby
p true and false
p true && false
# true, false
p false and true
p false && true
# false, false
p true or false
p false or true
# true, false
p true || false
p false || true
# true, true
What happened???? You mean to say AND and && is different. In the same way OR and || behave in a distinct manner. No.
Still I don’t have a proper answer, except telling that here jack is with “p” or “puts” which always evaluates the very first parameter in case of “and” or “or”. When we use symbolic “&&” / “||” may be some precedence rule, which forces print statement to evaluate by having both operands left and right as well. means
p true && false ==> becomes ===> p (ture && false) , whereas
p true and false ==> becomes ===> p true //takes only one argument.
Please if someone has got a proper answer let me know.
2 comments April 12, 2008