需要写比较点的方法在我的类称为点.鲁比(人名)



嗨,我已经在ruby中编写了这个点类,但我需要一个比较方法类,任何人有任何想法从哪里开始?

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

最新更新