Skip to content

Instantly share code, notes, and snippets.

@whitehat101
Created March 12, 2016 00:43
Show Gist options
  • Save whitehat101/3f4dcfee0ae5dba0ce0d to your computer and use it in GitHub Desktop.
Save whitehat101/3f4dcfee0ae5dba0ce0d to your computer and use it in GitHub Desktop.
A Ruby Circle Class
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