Class: Geometry::Triangle
- Inherits:
-
Object
- Object
- Geometry::Triangle
- Defined in:
- lib/geometrize.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
-
#validity ⇒ Object
Checking for Triangle Validity a + b > c.
Constructor Details
#initialize(a, b, c) ⇒ Triangle
Returns a new instance of Triangle.
5 6 7 8 9 10 |
# File 'lib/geometrize.rb', line 5 def initialize(a,b,c) @a = a.to_f @b = b.to_f @c = c.to_f @area = area end |
Instance Attribute Details
#a ⇒ Object
Returns the value of attribute a.
3 4 5 |
# File 'lib/geometrize.rb', line 3 def a @a end |
#b ⇒ Object
Returns the value of attribute b.
3 4 5 |
# File 'lib/geometrize.rb', line 3 def b @b end |
#c ⇒ Object
Returns the value of attribute c.
3 4 5 |
# File 'lib/geometrize.rb', line 3 def c @c end |
Instance Method Details
#area ⇒ Object
16 17 18 19 20 |
# File 'lib/geometrize.rb', line 16 def area perim = (self.perimeter/2) num_to_sqrt = perim * (perim - @a) * (perim - @b) * (perim - @c) Math.sqrt(num_to_sqrt) end |
#perimeter ⇒ Object
12 13 14 |
# File 'lib/geometrize.rb', line 12 def perimeter @a + @b + @c end |
#validity ⇒ Object
Checking for Triangle Validity a + b > c
24 25 26 27 28 29 30 31 |
# File 'lib/geometrize.rb', line 24 def validity if @a + @b <= @c || @c + @a <= @b || @b + @c <=@a puts "These is not a valid triangle" return false else return true end end |