-
-
Save plainprogrammer/bd8d6fd042081442ffe75c5d79f269bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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