Bird
0
0

When using the Ruby spaceship operator , what value is returned if the left operand is greater than the right operand?

easy📝 Conceptual Q1 of 15
Ruby - Operators and Expressions

When using the Ruby spaceship operator <=>, what value is returned if the left operand is greater than the right operand?

A-1
B1
C0
Dnil
Step-by-Step Solution
Solution:
  1. Step 1: Understand the spaceship operator

    The operator returns 1 if the left operand is greater than the right operand.
  2. Step 2: Compare operands

    Since the left is greater, the result is 1.
  3. Final Answer:

    1 -> Option B
  4. Quick Check:

    Left > Right returns 1 [OK]
Quick Trick: Left greater than right returns 1 [OK]
Common Mistakes:
  • Confusing 1 with -1
  • Assuming it returns true or false
  • Expecting nil for numeric comparisons

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes