Forum: Ruby == vs &&. Is there any difference?

4721860b9047417d5a97a2bcc11bce3d?d=identicon&s=25 Alex Le (iceberg_nyc)
on 2016-12-06 02:33
Hi,
I'm new to Ruby. Just started to take some online classes and now study
operators. Is there a difference if there is any between AND operator
"&&" and equality operator "==" ?
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-12-06 08:02
Eh .... do they have anything in common?

a == b evaluates to true, if a equals b (where the meaning of "equality"
depends on the types of a and b.

a && b evaluates to b, if a would evaluate to true in a boolean context,
and evaluates to a otherwise.

Hence, 5 == 9 is false, but 5 && 9 is 9.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.