Class: Rectangle

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

Direct Known Subclasses

Square

Instance Attribute Summary collapse

Attributes inherited from Polygon

#sides

Instance Method Summary collapse

Methods inherited from Quadrilateral

#_sides

Methods inherited from Polygon

#_sides

Constructor Details

#initialize(length, width) ⇒ Rectangle

Returns a new instance of Rectangle.



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

def initialize(length, width); @length, @width = length, width; end

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



25
26
27
# File 'lib/shapedoc.rb', line 25

def length
  @length
end

#widthObject (readonly)

Returns the value of attribute width.



25
26
27
# File 'lib/shapedoc.rb', line 25

def width
  @width
end

Instance Method Details

#areaObject



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

def area; @length*@width; end

#diagramObject



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

def diagram; "\u25AD"; end

#perimeterObject



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

def perimeter; @width*2+@length*2; end

#right_anglesObject



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

def right_angles; 4; end