Skip to content

Instantly share code, notes, and snippets.

@plainprogrammer
Last active December 8, 2017 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plainprogrammer/bd8d6fd042081442ffe75c5d79f269bf to your computer and use it in GitHub Desktop.
Save plainprogrammer/bd8d6fd042081442ffe75c5d79f269bf to your computer and use it in GitHub Desktop.
class P
def initialize x, y
@x, @y = x, y
end
attr_reader :x, :y
def d p
Math.sqrt((p.x - x) + (p.y - y))
end
end
class Point
def initialize x_coordinate, y_coordinate
@x_coordinate = x_coordinate
@y_coordinate = y_coordinate
end
attr_reader :x_coordinate, :y_coordinate
def distance_to other_point
x_difference = other_point.x_coordinate - self.x_coordinate
y_difference = other_point.y_coordinate - self.y_coordinate
Math.sqrt x_difference + y_difference
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment