All pastes #35552 Raw Edit

Anonymous

public text v1 · immutable
#35552 ·published 2006-01-02 20:19 UTC
rendered paste body
class Song
    include Comparable
    def initialize(name, duration)
        @name = name
        @duration = duration
    end
    def <(other)
        self.duration < other.duration
    end
    def <=>(other)
        self.duration <=> other.duration
    end
    def to_s
        "#{@name} is #{@duration} seconds long"
    end
end

song1 = Song.new("Pauls Song", 101)
song2 = Song.new("Saras Song", 100)

puts song1 < song2