Class: Geometry::Triangle

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#aObject

Returns the value of attribute a.



6
7
8
# File 'lib/geometry-mc.rb', line 6

def a
  @a
end

#bObject

Returns the value of attribute b.



6
7
8
# File 'lib/geometry-mc.rb', line 6

def b
  @b
end

#cObject

Returns the value of attribute c.



6
7
8
# File 'lib/geometry-mc.rb', line 6

def c
  @c
end

Instance Method Details

#areaObject



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

#perimeterObject



14
15
16
# File 'lib/geometry-mc.rb', line 14

def perimeter
	@a + @b + @c
end

#valid?Boolean

Returns:

  • (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