Class: Geometry::Triangle

Inherits:
Object
  • Object
show all
Defined in:
lib/geometry-mf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#aObject

Returns the value of attribute a.



3
4
5
# File 'lib/geometry-mf.rb', line 3

def a
  @a
end

#bObject

Returns the value of attribute b.



3
4
5
# File 'lib/geometry-mf.rb', line 3

def b
  @b
end

#cObject

Returns the value of attribute c.



3
4
5
# File 'lib/geometry-mf.rb', line 3

def c
  @c
end

Instance Method Details

#areaObject



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

#perimeterObject



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