-
-
Save yoshixmk/9018166 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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