Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumRubyComparable and spaceshipSingle-choice MCQ

A class includes `Comparable` and defines `<=>`. When `<=>` cannot meaningfully compare two operands, what should it return so methods like `<` raise the right error?

class Temp include Comparable attr_reader :deg def initialize(d) = @deg = d def <=>(other) return nil unless other.is_a?(Temp) deg <=> other.deg end end Temp.new(5) < 10