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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
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.
This topic is locked and can not be replied to.