class Point
attr_reader :x, :y
def initialize(x, y)
@x = x
@y = y
end
end
class Point
def distance_to(p2)
d1 = (@x - p2.x).pow(2)
d2 = (@y - p2.y).pow(2)
return Math.sqrt(d1 + d2)
end
end
point1 = Point.new(1, 2)
point2 = Point.new(2, 3)
distance = point1.distance_to(point2)
# distance is 1.4142
puts "distance is #{distance}"