Coder Social home page Coder Social logo

phase-3-metaprogramming-triangle-classification-lab's Introduction

Triangle Classification Lab

Learning Goals

  • Define a custom error class 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.

Define an instance method, #kind that returns, as a symbol, its type. The valid types are:

  • :equilateral
  • :isosceles
  • :scalene

Triangle types

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

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

Note: Several of the tests will be looking for the TriangleError to be raised. If you implement a rescue for it, however, the tests will not recognize that the error was raised. For purposes of this lab, therefore, you should not include a rescue.

Identifying Valid Triangles

A valid triangle must meet the following criteria:

  • Each side must be larger than 0.

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

Resources

phase-3-metaprogramming-triangle-classification-lab's People

Contributors

ahimmelstoss avatar aviflombaum avatar curiositypaths avatar deniznida avatar drakeltheryuujin avatar fislabstest avatar fs-lms-test-bot avatar gilmoursa avatar gj avatar ihollander avatar jmburges avatar juangongora avatar khartson avatar kthffmn avatar lizbur10 avatar loganhasson avatar maxwellbenton avatar realandrewcohn avatar sarogers avatar sophiedebenedetto avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.