Skip to content

Instantly share code, notes, and snippets.

@kazuhisa
Created February 15, 2014 08:11
Show Gist options
  • Save kazuhisa/9016006 to your computer and use it in GitHub Desktop.
Save kazuhisa/9016006 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
@yoshixmk
Copy link

ありがとうございます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment