Advanced
Ruby
Q97 / 100
What does "Comparable" combined with "<=>" returning nil signify, and how should methods like "<" handle it?
Correct! Well done.
Incorrect.
The correct answer is B) nil from <=> indicates the two objects are not comparable (e.g. incompatible types), and Comparable-derived methods like < will raise an ArgumentError in that case rather than returning a boolean
B
Correct Answer
nil from <=> indicates the two objects are not comparable (e.g. incompatible types), and Comparable-derived methods like < will raise an ArgumentError in that case rather than returning a boolean
Explanation
When <=> cannot meaningfully compare two objects (e.g. different incompatible types), it should return nil, and Comparable's derived operators raise an error rather than silently returning a misleading boolean.
Progress
97/100