开发者

need to write compare point method in my class called point . ruby

开发者 https://www.devze.com 2023-04-10 11:36 出处:网络
hi i have wrttien this points class in ruby but i need a compare method class to anybody a开发者_开发知识库ny ideas where to start?

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号