Class: Pulo::Square
- Inherits:
-
Object
- Object
- Pulo::Square
- Includes:
- Figure2D
- Defined in:
- lib/pulo/figure/figure2d.rb
Instance Attribute Summary collapse
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Attributes included from Figure2D
Instance Method Summary collapse
-
#initialize(width: nil, area: nil) ⇒ Square
constructor
A new instance of Square.
Methods included from Figure2D
Methods included from Quantity_Checker
Constructor Details
#initialize(width: nil, area: nil) ⇒ Square
Returns a new instance of Square.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pulo/figure/figure2d.rb', line 48 def initialize(width: nil, area: nil) raise "Square needs area or width." unless (area || width) quantity_check [area,Area] ,[width,Length] if area @area=area; @width=@area.rt(2) else @width=width; @area=@width**2 end @perimeter=@width*4 end |
Instance Attribute Details
#width ⇒ Object (readonly)
Returns the value of attribute width.
47 48 49 |
# File 'lib/pulo/figure/figure2d.rb', line 47 def width @width end |