Class: Rectangle
- Inherits:
-
Object
- Object
- Rectangle
- 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_one, side_two) ⇒ Rectangle
constructor
A new instance of Rectangle.
- #side_one=(val) ⇒ Object
- #side_two=(val) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(side_one, side_two) ⇒ Rectangle
Returns a new instance of Rectangle.
28 29 30 31 32 33 |
# File 'lib/shapelib.rb', line 28 def initialize(side_one, side_two) @side_one, @side_two = side_one, side_two @area = side_one * side_two @perimiter = (side_one * 2) + (side_two * 2) @diagonal = Math.sqrt(side_one ** 2 + side_two ** 2) end |
Instance Attribute Details
#area ⇒ Object (readonly)
Returns the value of attribute area.
26 27 28 |
# File 'lib/shapelib.rb', line 26 def area @area end |
#diagonal ⇒ Object (readonly)
Returns the value of attribute diagonal.
26 27 28 |
# File 'lib/shapelib.rb', line 26 def diagonal @diagonal end |
#perimiter ⇒ Object (readonly)
Returns the value of attribute perimiter.
26 27 28 |
# File 'lib/shapelib.rb', line 26 def perimiter @perimiter end |
Instance Method Details
#side_one=(val) ⇒ Object
43 44 45 46 |
# File 'lib/shapelib.rb', line 43 def side_one=(val) @side_one = val recalc end |
#side_two=(val) ⇒ Object
48 49 50 51 |
# File 'lib/shapelib.rb', line 48 def side_two=(val) @side_two = val recalc end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/shapelib.rb', line 53 def to_s "Rectangle: #{@side_one}-#{@side_two}" end |