Class: Square

Inherits:
Rectangle show all
Defined in:
lib/shapedoc.rb

Instance Attribute Summary collapse

Attributes inherited from Rectangle

#length, #width

Attributes inherited from Polygon

#sides

Instance Method Summary collapse

Methods inherited from Quadrilateral

#_sides

Methods inherited from Polygon

#_sides

Constructor Details

#initialize(side) ⇒ Square

Returns a new instance of Square.



33
# File 'lib/shapedoc.rb', line 33

def initialize(side); @side = side; end

Instance Attribute Details

#sideObject (readonly)

Returns the value of attribute side.



32
33
34
# File 'lib/shapedoc.rb', line 32

def side
  @side
end

Instance Method Details

#areaObject



35
# File 'lib/shapedoc.rb', line 35

def area; @side**2; end

#diagramObject



36
37
38
39
40
41
42
# File 'lib/shapedoc.rb', line 36

def diagram
  if @side < 25; "\u2b1e"
  elsif @side < 50; "\u25ab"
  elsif @side < 75; "\u25fb"
  else; "\u2b1c"
  end
end

#perimeterObject



34
# File 'lib/shapedoc.rb', line 34

def perimeter; @side*4; end