Skip to content

powercodeacademy/metaprgramming-additional-practice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Square Classification Lab

Learning Goals

  • Define a custom error class and use it
  • Work with geometric properties and validation

Instructions

Write a Square class that accepts four arguments on initialization. Each argument is a length of one of the four sides of the quadrilateral.

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

  • :square - all sides equal
  • :rectangle - opposite sides equal
  • :quadrilateral - any valid four-sided figure

The #kind method should raise a custom error, SquareError if the quadrilateral is invalid. Check out the hint below to understand what makes a quadrilateral valid.

Write a custom error class, SquareError and inherit it from StandardError. This custom error class should be defined in the same file as the Square class, inside the Square class definition, like this:

# lib/square.rb

class Square
  # square code

  class SquareError < StandardError
    # square error code
  end
end

Note: Several of the tests will be looking for the SquareError 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 Quadrilaterals

A valid quadrilateral must meet the following criteria:

  • Each side must be larger than 0.
  • The sum of the lengths of any three sides must exceed the length of the fourth side.

Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 20

Languages