svmartin
2/2/2017 - 1:03 AM

sieve_1_tear_down.rb

class Sieve
  attr_reader :numbers

  def initialize(limit)
    @numbers = [*(2..limit)]
  end

  def primes
    primes = []

    while (prime = numbers.delete_at(0))
      primes << prime
      numbers.delete_if { |number| number % prime == 0 }
    end

    primes
  end
end