Class: Square
- Inherits:
-
Object
- Object
- Square
- Defined in:
- lib/shapelib.rb
Instance Attribute Summary collapse
-
#area ⇒ Object
readonly
Returns the value of attribute area.
-
#diagonal ⇒ Object
readonly
Returns the value of attribute diagonal.
-
#perimiter ⇒ Object
readonly
Returns the value of attribute perimiter.
Instance Method Summary collapse
-
#initialize(side) ⇒ Square
constructor
A new instance of Square.
- #side=(val) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(side) ⇒ Square
Returns a new instance of Square.
5 6 7 8 9 10 |
# File 'lib/shapelib.rb', line 5 def initialize(side) @side = side @area = side ** 2 @perimiter = side * 4 @diagonal = Math.sqrt(side ** 2 + side ** 2) end |
Instance Attribute Details
#area ⇒ Object (readonly)
Returns the value of attribute area.
3 4 5 |
# File 'lib/shapelib.rb', line 3 def area @area end |
#diagonal ⇒ Object (readonly)
Returns the value of attribute diagonal.
3 4 5 |
# File 'lib/shapelib.rb', line 3 def diagonal @diagonal end |
#perimiter ⇒ Object (readonly)
Returns the value of attribute perimiter.
3 4 5 |
# File 'lib/shapelib.rb', line 3 def perimiter @perimiter end |
Instance Method Details
#side=(val) ⇒ Object
12 13 14 15 16 |
# File 'lib/shapelib.rb', line 12 def side=(val) @side = val @area = @side ** 2 @perimiter = @side * 4 end |
#to_s ⇒ Object
18 19 20 |
# File 'lib/shapelib.rb', line 18 def to_s "Square: #{@side}" end |