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 Rectangle

#right_angles

Methods inherited from Quadrilateral

#_sides

Methods inherited from Polygon

#_sides

Constructor Details

#initialize(side) ⇒ Square

Returns a new instance of Square.



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

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

Instance Attribute Details

#sideObject (readonly)

Returns the value of attribute side.



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

def side
  @side
end

Instance Method Details

#areaObject



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

def area; @side**2; end

#diagramObject



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

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

#perimeterObject



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

def perimeter; @side*4; end