Skip to content

Instantly share code, notes, and snippets.

@brianstorti
Created April 14, 2012 04:56
Show Gist options
  • Save brianstorti/2382191 to your computer and use it in GitHub Desktop.
Save brianstorti/2382191 to your computer and use it in GitHub Desktop.
<=>
class Tree
include Comparable
attr_accessor :age
def initialize(age)
@age = age
end
def <=> another_tree
age <=> another_tree.age
end
end
t1 = Tree.new(3)
t2 = Tree.new(3)
t3 = Tree.new(4)
puts t1 == t2 #true
puts t1 == t3 #false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment