Skip to content

Instantly share code, notes, and snippets.

@andreacfm
Created July 11, 2011 13:09
Show Gist options
  • Select an option

  • Save andreacfm/1075795 to your computer and use it in GitHub Desktop.

Select an option

Save andreacfm/1075795 to your computer and use it in GitHub Desktop.
ruby_comparable
class Person
include Comparable
attr_reader :name
def initialize(name)
@name = name
end
def <=> other
self.name <=> other.name
end
end
p1 = Person.new 'Andrea'
p2 = Person.new 'Fabio'
p3 = Person.new 'Luigi'
p p1 < p2 #true
p p2 < p1 #false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment