Class: Circle
- Inherits:
-
Object
- Object
- Circle
- Defined in:
- lib/hexa/shapes/circle.rb
Instance Attribute Summary collapse
-
#diameter ⇒ Object
Returns the value of attribute diameter.
-
#radius ⇒ Object
Returns the value of attribute radius.
Class Method Summary collapse
-
.area(radius = 1) ⇒ Float
Same behavior as area but can be called just passing the radius.
Instance Method Summary collapse
-
#area ⇒ Float
The area of the circle.
-
#initialize(options = {}) ⇒ Circle
constructor
Constructor for the Circle object.
Constructor Details
#initialize(options = {}) ⇒ Circle
Constructor for the Circle object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hexa/shapes/circle.rb', line 8 def initialize( = {}) if [:radius] @radius = [:radius] @diameter = [:radius] * 2 elsif [:diameter] @radius = [:diameter] / 2 @diameter = [:diameter] else @radius = 1 @diameter = 2 end end |
Instance Attribute Details
#diameter ⇒ Object
Returns the value of attribute diameter.
3 4 5 |
# File 'lib/hexa/shapes/circle.rb', line 3 def diameter @diameter end |
#radius ⇒ Object
Returns the value of attribute radius.
3 4 5 |
# File 'lib/hexa/shapes/circle.rb', line 3 def radius @radius end |
Class Method Details
.area(radius = 1) ⇒ Float
Same behavior as area but can be called just passing the radius
29 30 31 |
# File 'lib/hexa/shapes/circle.rb', line 29 def self.area(radius = 1) Math::PI * (radius ** 2) end |
Instance Method Details
#area ⇒ Float
Returns the area of the circle.
22 23 24 |
# File 'lib/hexa/shapes/circle.rb', line 22 def area Math::PI * (@radius ** 2) end |