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.

April 12, 2008 at 8:01 pm 2 comments


Categories

posts[:recent]

@@name = PRAYAS

This blog has more intention for my self reference@24×7. But if some search engine crawler directs you to my page, believe I may learn form your comments or feedback. Hence feel free to comment good or bad!
prayas2010@gmail.com

visitors[:since_Mar'08]

free web counter

Prayas@Nikon

A colored life

Chhweet Kidss

An independent world

More Photos

Feeds


Follow

Get every new post delivered to your Inbox.