Class: Geometry::Triangle
- Inherits:
-
Object
- Object
- Geometry::Triangle
- Defined in:
- lib/geometry-mf.rb
Instance Attribute Summary collapse
-
#a ⇒ Object
Returns the value of attribute a.
-
#b ⇒ Object
Returns the value of attribute b.
-
#c ⇒ Object
Returns the value of attribute c.
Instance Method Summary collapse
- #area ⇒ Object
-
#initialize(a, b, c) ⇒ Triangle
constructor
A new instance of Triangle.
- #perimeter ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(a, b, c) ⇒ Triangle
5 6 7 8 9 |
# File 'lib/geometry-mf.rb', line 5 def initialize(a,b,c) @a = a.to_f @b = b.to_f @c = c.to_f end |
Instance Attribute Details
#a ⇒ Object
Returns the value of attribute a.
3 4 5 |
# File 'lib/geometry-mf.rb', line 3 def a @a end |
#b ⇒ Object
Returns the value of attribute b.
3 4 5 |
# File 'lib/geometry-mf.rb', line 3 def b @b end |
#c ⇒ Object
Returns the value of attribute c.
3 4 5 |
# File 'lib/geometry-mf.rb', line 3 def c @c end |
Instance Method Details
#area ⇒ Object
15 16 17 18 19 |
# File 'lib/geometry-mf.rb', line 15 def area perim = (@a+@b+@c)/2 num = perim * ((perim - @a) * (perim - @b) * (perim - @c)) Math.sqrt(num) end |
#perimeter ⇒ Object
11 12 13 |
# File 'lib/geometry-mf.rb', line 11 def perimeter @a + @b + @c end |
#valid? ⇒ Boolean
21 22 23 24 25 26 27 |
# File 'lib/geometry-mf.rb', line 21 def valid? if (@a+@b>@c) && (@b+@c>@a) && (@c+@a>@b) return true else return false end end |