The Rubyist's Loop


#1

Hey there,

I am doing the refractor exercise and until now in every exercise I typed in the exact solution, still the interpreter won’t accept it. The when i hit get code, i just get the code i already typed in and it is valid. It feels really like codeacademy is making fun of you. Here i substituted the for loop with n.times. Still doesn’t work.

$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)

return "n must be an integer." unless n.is_a? Integer
  
return "n must be greater than 0." if n <= 0
  
  prime_array ||= [] 
  
  prime = Prime.new
  
  n.times { prime_array.push(prime.next) }

  prime_array
end

first_n_primes(10)

#2

Ditto. Same problem. This is a real drag. how can you learn, if, when you do it right, you are marked “wrong”?


#3

I think the whole set of exercises is buggy. I am currently creating intentional mistakes so I can click “Get code” from the pop-up to advance to the next exercise set.


#4

Same here, really annoying…


#5

Hi. The issue appears to be that in the latest Ruby release Prime.new was deprecated.

From the documentation “Prime.new is now obsolete. Use Prime.instance.each or simply Prime.each.”

I changed the following line:

prime = Prime.new

to:

prime = Prime.each

and all of the steps in the exercise now work.

http://ruby-doc.org/stdlib-1.9.3/libdoc/prime/rdoc/Prime.html#method-i-each-label-Note


#6