-1

嗨,我在 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
4

1 回答 1

1
class Point
  def == p
     return false unless p.kind_of? Point
     x == p.x and y == p.y
  end
end
于 2011-10-03T11:17:41.903 回答