Class: Circle
- Inherits:
-
Object
- Object
- Circle
- Defined in:
- lib/shapelib.rb
Instance Attribute Summary collapse
-
#area ⇒ Object
readonly
Returns the value of attribute area.
-
#circumference ⇒ Object
readonly
Returns the value of attribute circumference.
-
#diameter ⇒ Object
readonly
Returns the value of attribute diameter.
-
#radius ⇒ Object
Returns the value of attribute radius.
Instance Method Summary collapse
-
#initialize(radius) ⇒ Circle
constructor
A new instance of Circle.
- #to_s ⇒ Object
Constructor Details
#initialize(radius) ⇒ Circle
Returns a new instance of Circle.
105 106 107 108 109 110 111 112 |
# File 'lib/shapelib.rb', line 105 def initialize(radius) @PI = Math::PI @radius = radius @diameter = radius * 2 @circumference = @diameter * @PI @area = @PI * radius ** 2 @anti_area = @diameter ** 2 - @area end |
Instance Attribute Details
#area ⇒ Object (readonly)
Returns the value of attribute area.
103 104 105 |
# File 'lib/shapelib.rb', line 103 def area @area end |
#circumference ⇒ Object (readonly)
Returns the value of attribute circumference.
103 104 105 |
# File 'lib/shapelib.rb', line 103 def circumference @circumference end |
#diameter ⇒ Object (readonly)
Returns the value of attribute diameter.
103 104 105 |
# File 'lib/shapelib.rb', line 103 def diameter @diameter end |
#radius ⇒ Object
Returns the value of attribute radius.
103 104 105 |
# File 'lib/shapelib.rb', line 103 def radius @radius end |
Instance Method Details
#to_s ⇒ Object
128 129 130 |
# File 'lib/shapelib.rb', line 128 def to_s "Circle: #{@radius}" end |