Yesterday I came to find this exercise pretty interesting, it called back the distant geometry lessons I’ve had in the past.

This was compromised of two separate test files and one which we will code the project named triangle.rb, was accomplished by first passing the test for building a triangle and last to raise the Exceptions or errors.

My answer was the following one:

def triangle(a, b, c)
if a <= 0 || b <= 0 || c <= 0
raise TriangleError, "Size must be over 0."
end
if ((a+b) <= c || ((a+c) <= b) || ((b+c) <= a)
raise TriangleError, "Illegal triangle!"
end
# end of error raise
if (a == b) && (b == c)
:equilateral
elsif (a == b) || (a == c) || (b == c)
:isosceles
else
:scalene
end
end
class TriangleError < StandardError
end

This might not be the most neat and correct Ruby syntax but I’ll get there.

### Like this:

Like Loading...