Logic Quiz
What does "cat" >= "dog"
return?
"cat"
true
false
"cat"
is alphabetically less than (prior to)"dog"
; therefore, the operation returns false
. Both operands are strings, so the comparison is valid.What does "cat" != []
return?
"cat"
true
false
"cat"
does not equal an empty array; therefore, the operation returns true
. One can check for equality across data types, so the comparison is valid.What does [] < [true]
return?
"cat"
true
false
What does 2 < 3 && 2.even?
return?
true
false
2 < 3 and 2.even? are true (both expressions evaluate to true), the statement returns true.
What does 2.odd? && 2 < 3
return?
true
false
2.odd? evaluates to false, and the operator is &&, the statement short-circuits and returns false regardless of the second operand.
What does 2.odd? || 2 < 3
return?
true
false
2.odd? evaluates to false, and the operator is ||, the Ruby interpreter does not short-circuit and evaluates the second operand. Because 2 < 3 evaluates to true, the statement returns true.