Class: Pulo::Square

Inherits:
Object
  • Object
show all
Includes:
Figure2D
Defined in:
lib/pulo/figure/figure2d.rb

Instance Attribute Summary collapse

Attributes included from Figure2D

#area, #perimeter

Instance Method Summary collapse

Methods included from Figure2D

#*

Methods included from Quantity_Checker

#quantity_check

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

#widthObject (readonly)

Returns the value of attribute width.


47
48
49
# File 'lib/pulo/figure/figure2d.rb', line 47

def width
  @width
end