Created
April 14, 2012 04:56
-
-
Save brianstorti/2382191 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 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