#!/usr/bin/env ruby require 'pp' class Song attr_reader :name, :pos def initialize(name, pos) @name = name @pos = pos end def <=>(other) if(@pos < other.pos) return -1 elsif(@pos == other.pos) return 0 elsif(@pos > other.pos) return 1 end end end list = [] list << Song.new("abc", 5) list << Song.new("bcd", 2) list << Song.new("cde", 1) list << Song.new("def", 3) list << Song.new("efg", 4) pp list.sort