嗨我已经在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
答案 0 :(得分:1)
class Point
def == p
return false unless p.kind_of? Point
x == p.x and y == p.y
end
end