The Refactor Factory


#1
$VERBOSE = nil    # We'll explain this at the end of the lesson.
require 'prime'   # This is a module. We'll cover these soon!

def first_n_primes(n)

  puts "n must be an integer." unless n.is_a? Integer
  
  puts "n must be greater than 0." if n <= 0
  
  prime_array = [] if prime_array.nil?
  
  prime = Prime.new
  for num in (1..n)
    prime_array.push(prime.next)
  end
  return prime_array
end

first_n_primes(10)

why is it telling me …Remember, you don’t need any 'end’s with one-line ‘if’ and ‘unless’ statements in regards to the lines i have stared. Could some one advise if i am missing something please


#2

Chances are there is no error with those lines, only something else might have gone wrong that the SCT does not have a message for so uses the one it has.

Since this lesson was written there may have been a change in the version of Ruby that is in use, making some the code obsolete or deprecated.

Please post a link to the exercise so we can further test this assumption.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.