Class: Pulo::Cylinder
- Inherits:
-
Object
- Object
- Pulo::Cylinder
- Includes:
- Figure3D
- Defined in:
- lib/pulo/figure/figure3d.rb
Instance Attribute Summary collapse
-
#face ⇒ Object
readonly
Returns the value of attribute face.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Attributes included from Figure3D
Instance Method Summary collapse
-
#initialize(face: nil, length: nil, volume: nil, radius: nil, diameter: nil) ⇒ Cylinder
constructor
A new instance of Cylinder.
Methods included from Quantity_Checker
Constructor Details
#initialize(face: nil, length: nil, volume: nil, radius: nil, diameter: nil) ⇒ Cylinder
Returns a new instance of Cylinder.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/pulo/figure/figure3d.rb', line 98 def initialize (face: nil, length: nil, volume: nil, radius: nil, diameter: nil) quantity_check [face,Circle] ,[length,Length] , [volume,Volume], [radius, Length], [diameter, Length] raise 'Cylinder needs length and face or volume and length or volume and radius or diameter.' unless (face && length) || (volume && length) || (volume && (radius || diameter)) || (length && (radius || diameter)) if face and length @face=face @length=length @volume=@face.area*@length else if volume and length @length=length @volume=volume @face=Circle.new(area: @volume/@length) else if (radius or diameter) and volume @face=Circle.new(radius: radius, diameter: diameter) @volume=volume @length=volume/@face.area else @face=Circle.new(radius: radius, diameter: diameter) @length=length @volume=@face.area*@length end end end @surfacearea=@face.area*2+@face.perimeter*@length @area=@face.area @radius=@face.radius end |
Instance Attribute Details
#face ⇒ Object (readonly)
Returns the value of attribute face.
97 98 99 |
# File 'lib/pulo/figure/figure3d.rb', line 97 def face @face end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
97 98 99 |
# File 'lib/pulo/figure/figure3d.rb', line 97 def length @length end |