Class: Rectangle
- Inherits:
-
Quadrilateral
- Object
- Polygon
- Quadrilateral
- Rectangle
- Defined in:
- lib/shapedoc.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Attributes inherited from Polygon
Instance Method Summary collapse
- #area ⇒ Object
- #diagram ⇒ Object
-
#initialize(length, width) ⇒ Rectangle
constructor
A new instance of Rectangle.
- #perimeter ⇒ Object
- #right_angles ⇒ Object
Methods inherited from Quadrilateral
Methods inherited from Polygon
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
#length ⇒ Object (readonly)
Returns the value of attribute length.
25 26 27 |
# File 'lib/shapedoc.rb', line 25 def length @length end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
25 26 27 |
# File 'lib/shapedoc.rb', line 25 def width @width end |
Instance Method Details
#area ⇒ Object
28 |
# File 'lib/shapedoc.rb', line 28 def area; @length*@width; end |
#diagram ⇒ Object
29 |
# File 'lib/shapedoc.rb', line 29 def diagram; "\u25AD"; end |
#perimeter ⇒ Object
27 |
# File 'lib/shapedoc.rb', line 27 def perimeter; @width*2+@length*2; end |
#right_angles ⇒ Object
30 |
# File 'lib/shapedoc.rb', line 30 def right_angles; 4; end |