Equality comparisons can be used on all Ruby objects, including Strings
, Integers
, Floats
, Arrays
, Hashes
, etc:
==
(equal to?)!=
(not equal to?)
Note the difference between =
and ==
Numeric comparisons are used primarily on Integers
and Floats
:
>
(greater than?)<
(less than?)>=
(greater than or equal to?)<=
(less than or equal to?)
The "result" of any of these relational operator is a boolean. Recall that there are two kinds of boolean objects:
true
false
# Is one greater than zero?
1 > 0
# => true
# Is the string 'hello' equal to the string 'hello'?
"hello" == "hello"
# => true
Logical Operators are used to test two or more relationships together. There are three main logical oeprators that we would use:
-
&&
(and) Outcome of p && q is true only if both p and q are true -
||
(or) Outcome ofp || q
istrue
if eitherp
orq
istrue
-
!
(not) Outcome of!p
istrue
ifp
isfalse
. Outcome of!p
isfalse
ifp
istrue
.