Class: Triangle
- Inherits:
-
Object
- Object
- Triangle
- Defined in:
- lib/shapelib.rb
Instance Attribute Summary collapse
-
#area ⇒ Object
readonly
Returns the value of attribute area.
-
#perimiter ⇒ Object
readonly
Returns the value of attribute perimiter.
-
#semiperimiter ⇒ Object
readonly
Returns the value of attribute semiperimiter.
-
#side_one ⇒ Object
Returns the value of attribute side_one.
-
#side_three ⇒ Object
Returns the value of attribute side_three.
-
#side_two ⇒ Object
Returns the value of attribute side_two.
Instance Method Summary collapse
-
#initialize(side_one, side_two, side_three) ⇒ Triangle
constructor
A new instance of Triangle.
- #to_s ⇒ Object
Constructor Details
#initialize(side_one, side_two, side_three) ⇒ Triangle
Returns a new instance of Triangle.
64 65 66 67 68 69 |
# File 'lib/shapelib.rb', line 64 def initialize(side_one, side_two, side_three) @side_one, @side_two, @side_three = side_one, side_two, side_three @perimiter = side_one + side_two + side_three @semiperimiter = @perimiter/2.0 @area = Math.sqrt(((side_one + side_two + side_three) * ((side_one * -1) + side_two + side_three) * (side_one - side_two + side_three) * (side_one + side_two - side_three)) / 16.0) end |
Instance Attribute Details
#area ⇒ Object (readonly)
Returns the value of attribute area.
62 63 64 |
# File 'lib/shapelib.rb', line 62 def area @area end |
#perimiter ⇒ Object (readonly)
Returns the value of attribute perimiter.
62 63 64 |
# File 'lib/shapelib.rb', line 62 def perimiter @perimiter end |
#semiperimiter ⇒ Object (readonly)
Returns the value of attribute semiperimiter.
62 63 64 |
# File 'lib/shapelib.rb', line 62 def semiperimiter @semiperimiter end |
#side_one ⇒ Object
Returns the value of attribute side_one.
62 63 64 |
# File 'lib/shapelib.rb', line 62 def side_one @side_one end |
#side_three ⇒ Object
Returns the value of attribute side_three.
62 63 64 |
# File 'lib/shapelib.rb', line 62 def side_three @side_three end |
#side_two ⇒ Object
Returns the value of attribute side_two.
62 63 64 |
# File 'lib/shapelib.rb', line 62 def side_two @side_two end |
Instance Method Details
#to_s ⇒ Object
94 95 96 |
# File 'lib/shapelib.rb', line 94 def to_s "Triangle: #{@side_one}-#{@side_two}-#{@side_three}" end |