Class: Pulo::Rectangle
- Inherits:
-
Object
- Object
- Pulo::Rectangle
- Includes:
- Figure2D
- Defined in:
- lib/pulo/figure/figure2d.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Attributes included from Figure2D
Instance Method Summary collapse
- #extrusion_figure ⇒ Object
-
#initialize(area: nil, width: nil, height: nil) ⇒ Rectangle
constructor
A new instance of Rectangle.
Methods included from Figure2D
Methods included from Quantity_Checker
Constructor Details
#initialize(area: nil, width: nil, height: nil) ⇒ Rectangle
Returns a new instance of Rectangle.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/pulo/figure/figure2d.rb', line 69 def initialize(area: nil, width: nil, height: nil) quantity_check [area,Area] ,[width,Length] , [height,Length] raise 'Rectangle needs width and height or area and width or height.' unless (width && height) || (area && (width || height)) if area @area=area if width @width=width; @height=@area/@width else @height=height; @width=@area/@height end else @width=width; @height=height @area=@width*@height end @perimeter=@width*2+@height*2 end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
64 65 66 |
# File 'lib/pulo/figure/figure2d.rb', line 64 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
64 65 66 |
# File 'lib/pulo/figure/figure2d.rb', line 64 def width @width end |
Instance Method Details
#extrusion_figure ⇒ Object
66 67 68 |
# File 'lib/pulo/figure/figure2d.rb', line 66 def extrusion_figure Cuboid end |