Skip to content

Instantly share code, notes, and snippets.

@yoshixmk
Forked from kazuhisa/UFO
Created February 15, 2014 11:39
Show Gist options
  • Save yoshixmk/9018166 to your computer and use it in GitHub Desktop.
Save yoshixmk/9018166 to your computer and use it in GitHub Desktop.
class Hoge
include Comparable
attr_accessor :age
def initialize(age)
@age = age
end
def <=>(other)
self.age <=> other.age
end
end
list = [Hoge.new(20), Hoge.new(10), Hoge.new(15)]
list.sort.each do |v|
puts v.age
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment