concept comparable module in category ruby

appears as: Comparable module
The Well-Grounded Rubyist, Third Edition

This is an excerpt from Manning's book The Well-Grounded Rubyist, Third Edition.

The < method (along with >, >=, <=, ==, !=, and between?) is defined in terms of <=>, inside the Comparable module. (b.between?(a,c) tells you whether b > a and b < c.)

Listing 10.4. Mixing in the Comparable module
class Painting
  include Comparable          #1
  attr_reader :price
  def initialize(price)
    @price = price
  end
  def to_s
    "My price is #{price}."
  end
  def <=>(other_painting)
    self.price <=> other_painting.price
  end
end


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":1,\"ch\":30},{\"line\":1,\"ch\":32}]]"}
!@%STYLE%@!