Ruby Koans Triangle

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."

  if ((a+b) <= c || ((a+c) <= b) || ((b+c) <= a)
    raise TriangleError, "Illegal triangle!"

# end of error raise

  if (a == b) && (b == c)
  elsif (a == b) || (a == c) || (b == c)

class TriangleError < StandardError

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


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s