Class: Square
- Inherits:
-
Rectangle
- Object
- Polygon
- Quadrilateral
- Rectangle
- Square
- Defined in:
- lib/shapedoc.rb
Instance Attribute Summary collapse
-
#side ⇒ Object
readonly
Returns the value of attribute side.
Attributes inherited from Rectangle
Attributes inherited from Polygon
Instance Method Summary collapse
- #area ⇒ Object
- #diagram ⇒ Object
-
#initialize(side) ⇒ Square
constructor
A new instance of Square.
- #perimeter ⇒ Object
Methods inherited from Rectangle
Methods inherited from Quadrilateral
Methods inherited from Polygon
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
#side ⇒ Object (readonly)
Returns the value of attribute side.
33 34 35 |
# File 'lib/shapedoc.rb', line 33 def side @side end |
Instance Method Details
#area ⇒ Object
36 |
# File 'lib/shapedoc.rb', line 36 def area; @side**2; end |
#diagram ⇒ Object
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 |
#perimeter ⇒ Object
35 |
# File 'lib/shapedoc.rb', line 35 def perimeter; @side*4; end |