FAQ: The Refactor Factory - Less is More

This community-built FAQ covers the “Less is More” exercise from the lesson “The Refactor Factory”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Ruby

FAQs on the exercise Less is More

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hello. I’m kindof confused by this lesson:
https://www.codecademy.com/courses/learn-ruby/lessons/the-refactor-factory/exercises/less-is-more

It says to remove one of the return statements. But you can’t remove the return from the Unless or the If statement. The way to pass the lesson is to remove the very last line:
first_n_primes(10)

Isn’t this calling the method? It doesn’t seem to be a return statement. It helps to refactor the code, but I don’t understand why the lesson calls it a return statement. :confused:

EDIT: Nevermind, I made a mistake. I actually changed this line first:
return Prime.first n

This is what the lesson is about. I deleted the method call & it was unrelated. My bad! :sweat_smile:

it says to remove the unnecessary return keywords, but both of them are necessary so just don’t change anything.

require 'prime'   # This is a module. We'll cover these soon!

def first_n_primes(n)
  return "n must be an integer." unless n.is_a? Integer
  return "n must be greater than 0." if n <= 0
  Prime.first n
end

first_n_primes(10)

They say that you should remove the last “return” because it’s not necessary

require ‘prime’ # This is a module. We’ll cover these soon!

def first_n_primes(n)
return “n must be an integer.” unless n.is_a? Integer
return “n must be greater than 0.” if n <= 0
return Prime.first n
end

first_n_primes(10)

so the result will be the same just removing the last return:

require ‘prime’ # This is a module. We’ll cover these soon!

def first_n_primes(n)
return “n must be an integer.” unless n.is_a? Integer
return “n must be greater than 0.” if n <= 0
Prime.first n
end

first_n_primes(10)

but I don’t get why it is not necessary

Ruby implicitly returns the value in the last line of the method.

3 Likes