Class: Circle

Inherits:
Object
  • Object
show all
Defined in:
lib/shapelib.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#areaObject (readonly)

Returns the value of attribute area.



103
104
105
# File 'lib/shapelib.rb', line 103

def area
  @area
end

#circumferenceObject (readonly)

Returns the value of attribute circumference.



103
104
105
# File 'lib/shapelib.rb', line 103

def circumference
  @circumference
end

#diameterObject (readonly)

Returns the value of attribute diameter.



103
104
105
# File 'lib/shapelib.rb', line 103

def diameter
  @diameter
end

#radiusObject

Returns the value of attribute radius.



103
104
105
# File 'lib/shapelib.rb', line 103

def radius
  @radius
end

Instance Method Details

#to_sObject



128
129
130
# File 'lib/shapelib.rb', line 128

def to_s
  "Circle: #{@radius}"
end