Class: Geometry::Triangle

Inherits:
Object
  • Object
show all
Defined in:
lib/geometrize.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#aObject

Returns the value of attribute a.



3
4
5
# File 'lib/geometrize.rb', line 3

def a
  @a
end

#bObject

Returns the value of attribute b.



3
4
5
# File 'lib/geometrize.rb', line 3

def b
  @b
end

#cObject

Returns the value of attribute c.



3
4
5
# File 'lib/geometrize.rb', line 3

def c
  @c
end

Instance Method Details

#areaObject



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

#perimeterObject



12
13
14
# File 'lib/geometrize.rb', line 12

def perimeter
  @a + @b + @c
end

#validityObject

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