Bird
0
0

Why does Ruby's case/when statement use the === operator internally to compare values?

hard📝 Conceptual Q10 of 15
Ruby - Control Flow

Why does Ruby's case/when statement use the === operator internally to compare values?

ABecause <code>===</code> is the same as <code>==</code> in Ruby
BBecause <code>===</code> performs strict type checking
CBecause <code>===</code> allows flexible matching like ranges and classes
DBecause <code>===</code> raises an error if values don't match
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of === in case/when

    Ruby uses === to allow matching with ranges, classes, regex, and other flexible comparisons.
  2. Step 2: Compare with other operators

    == checks equality, but === is more flexible and used internally by case.
  3. Final Answer:

    === allows flexible matching like ranges and classes -> Option C
  4. Quick Check:

    case uses === for flexible matching [OK]
Quick Trick: case uses === for flexible matching internally [OK]
Common Mistakes:
MISTAKES
  • Confusing === with ==
  • Thinking === does strict type check
  • Believing === raises errors on mismatch

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes