Skip to content

learn-co-students/triangle-classification-seattle-web-060319

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Triangle

Objectives

  1. Define a custom error and use it.

Instructions

  • Write a Triangle class that accepts three arguments on initialization. Each argument is a length of one of the three sides of the triangle.

  • Give your Triangles an instance method, kind that returns, as a symbol, its type. The valid types are:

  1. :equilateral

  2. :isosceles

  3. :scalene

  • The kind method should raise a custom error, TriangleError if the triangle is invalid. Check out the hint below to understand what makes a triangle invalid. Write a custom error class, TriangleError and inherit it from StandardError. This custom error class should be defined in the same file as the Triangle class, inside the Triangle class definition. Like this:
# lib/triangle.rb

class Triangle
  # triangle code

  class TriangleError < StandardError
    # triangle error code
  end
end

Hint

The sum of the lengths of any two sides of a triangle always exceeds the length of the third side. This is a principle known as the triangle inequality.

Further, each side must be larger than 0.

Resources

View Triangle on Learn.co and start learning to code for free.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages