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

A class includes `Comparable` and its `<=>` returns 0 for two distinct instances. What is true about `==` and `eql?` for them?

class Money include Comparable attr_reader :cents def initialize(c) = @cents = c def <=>(o) = cents <=> o.cents end a = Money.new(100) b = Money.new(100) puts [a == b, a.eql?(b)].inspect