10 Things Every Java Programmer Should Know About Ruby

Reuse the Mix-in

A mix-in allows the commonality to be factored out.

module LessComparable
  def >(other)
    other < self
  end
  # Other methods defined in terms of less than:
  #     <=, >=, ==
end
class Pair
  include LessComparable
  attr_accessor :first, :second
  # ...
  def <(other)
    (first < other.first) ||
      (first == other.first && second < other.second)
  end
end