Class: Geometry::Triangle
- Inherits:
-
Object
- Object
- Geometry::Triangle
- Defined in:
- lib/geometry-mc.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
Returns a new instance of Triangle.
8 9 10 11 12 |
# File 'lib/geometry-mc.rb', line 8 def initialize(a, b, c) @a = a @b = b @c = c end |
Instance Attribute Details
#a ⇒ Object
Returns the value of attribute a.
6 7 8 |
# File 'lib/geometry-mc.rb', line 6 def a @a end |
#b ⇒ Object
Returns the value of attribute b.
6 7 8 |
# File 'lib/geometry-mc.rb', line 6 def b @b end |
#c ⇒ Object
Returns the value of attribute c.
6 7 8 |
# File 'lib/geometry-mc.rb', line 6 def c @c end |
Instance Method Details
#area ⇒ Object
18 19 20 21 22 |
# File 'lib/geometry-mc.rb', line 18 def area half_p = (self.perimeter.to_f/2) num_to_sqrt = half_p * (half_p - @a) * (half_p - @b) * (half_p - @c) Math.sqrt(num_to_sqrt) end |
#perimeter ⇒ Object
14 15 16 |
# File 'lib/geometry-mc.rb', line 14 def perimeter @a + @b + @c end |
#valid? ⇒ Boolean
24 25 26 27 28 29 30 |
# File 'lib/geometry-mc.rb', line 24 def valid? if (@a + @b > @c) && (@a + @c > @b) && (@b + @c > @a) true else false end end |