Sha256: 1bb6723e3355683b73948f05a49fdcc16e19c517a38328974ca1a1c3ac86a641

Contents?: true

Size: 792 Bytes

Versions: 1

Compression:

Stored size: 792 Bytes

Contents

require 'pry'

module Geometry

	class Triangle
		attr_accessor :a, :b, :c

		def initialize(a, b, c)
			@a = a
			@b = b
			@c = c
		end

		def perimeter
			@a + @b + @c
		end	

		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

		def valid?
			if (@a + @b > @c) && (@a + @c > @b) && (@b + @c > @a)
				true
			else
				false
			end
		end

	end

	class Circle
		attr_accessor :r 

		def initialize(r)
			@r = r
			@d = 2 * r
		end

		def area
			Math::PI * (@r ** 2)
		end

		def perimeter
			Math::PI * @d
		end

	end

	class Rectangle
		attr_accessor :l, :w

		def initialize(l, w)
			@l = l
			@w = w
		end

		def perimeter
			2 * (@l + @w)
		end

		def area
			@l * @w
		end

	end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
geometry-mc-0.1.0 lib/geometry-mc.rb