Learn

One of the most common suggestions when it comes to writing is to omit needless words, and it applies just as much to writing Ruby as writing stories.

There are two control structures to change here:

  1. The unless block:

    unless n.is_a? Integer return "n must be an integer." end
  2. The if block below the unless block:

    if n <= 0 return "n must be greater than 0." end

Both blocks can be simplified using the zen of Ruby!

Instructions

1.

Refactor the code in the editor to use single-line ifs and unlesss.

Take this course for free

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?