class Point
attr_accessor :x, :y
def initialize(x, y)
@x, @y = x, y
end
def +(other)
@x = @x + other.x
@y = @y + other.y
return Point.new(@x, @y)
end
end
p1 = Point.new(1, 1)
p2 = Point.new(2, 2)
p3 = p1 + p2
# p3.x is 3 and p3.y is 3
puts "(x, y) is (#{p3.x}, #{p3.y})"
p3 += Point.new(3, 5)
# p3.x is 6 and p3.y is 8
puts "(x, y) is (#{p3.x}, #{p3.y})"