Created
March 12, 2016 00:43
-
-
Save whitehat101/3f4dcfee0ae5dba0ce0d to your computer and use it in GitHub Desktop.
A Ruby Circle Class
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
module WhiteHat101 | |
class Circle | |
attr_accessor :origin, :radius | |
def initialize origin = [0,0], radius = 0 | |
@origin = origin | |
@radius = radius | |
end | |
def self.origin_point origin, point | |
radius = Math.sqrt origin.zip(point) | |
.map {|a,b| (a - b)**2 } | |
.inject(0.0, :+) | |
new origin, radius | |
end | |
def where point | |
radius = Math.sqrt origin.zip(point) | |
.map {|a,b| (a - b)**2 } | |
.inject(0.0, :+) | |
@radius <=> radius | |
end | |
end | |
end | |
WhiteHat101::Circle.origin_point [1,2], [3,4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment