joelibaceta
9/21/2015 - 6:58 AM

Primes.rb

# Implement a Primes class with a class method first(n)
#   that returns an array of the first n prime numbers.

class Primes 
  def self.first(total, primes=[2], n=2)
    primes.count >= total ? primes : (eval ((2..n-1).map{|j| (n % j == 0) ? false : true}).join(" && ")) ? first(total, primes.push(n), n+1) : first(total, primes, n+1)   
  end  
end