Skip to content

Instantly share code, notes, and snippets.

@plainprogrammer plainprogrammer/brevity.rb Secret

Last active Dec 8, 2017
Embed
What would you like to do?
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
You can’t perform that action at this time.