Intermediate
Ruby
Q52 / 100
What does "case/when" provide that an if/elsif chain also does, and how does it differ semantically?
Correct! Well done.
Incorrect.
The correct answer is B) case/when uses the "===" operator (case equality) for each "when" clause, which allows matching against ranges, classes, regexes, and more, not just direct equality
B
Correct Answer
case/when uses the "===" operator (case equality) for each "when" clause, which allows matching against ranges, classes, regexes, and more, not just direct equality
Explanation
case/when calls "===" on each candidate, which different classes implement differently (e.g. Range#=== checks membership, Class#=== checks instance, Regexp#=== checks match), giving more flexible matching than plain equality.
Progress
52/100