S hr kan se ut.
public ruby v1 · immutable#!/usr/bin/env rubyrequire '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 endendlist = []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