hi i have wrttien this points class in ruby but i need a compare method class to anybody a开发者_开发知识库ny ideas where to start?
class Point
attr_reader :x, :y
def initialize x,y
@x = x
@y = y
end
def addpoint(x,y) # used to add points
Point.new(@x+x, @y+y)
end
def to_s
x.to_s+" , "+y.to_s # used to change from object to strings
end
end
class Point
def == p
return false unless p.kind_of? Point
x == p.x and y == p.y
end
end
精彩评论