Skip to content

Instantly share code, notes, and snippets.

@koskoci
Created July 27, 2018 00:19
Show Gist options
  • Save koskoci/fb6cc898b238ec493a9d992afe132c36 to your computer and use it in GitHub Desktop.
Save koskoci/fb6cc898b238ec493a9d992afe132c36 to your computer and use it in GitHub Desktop.
require 'prime'
class Primer < Prime::EratosthenesSieve
def self.call(limit)
new.call(limit)
end
def call(limit)
(1..limit).to_a.inject([]) do |arr, n|
arr << get_nth_prime(n)
arr
end
end
def get_nth_prime(n)
super
end
end
@koskoci
Copy link
Author

koskoci commented Jul 27, 2018

Returns the first n prime numbers. Exercise to expose the private instance method Prime::EratosthenesSieve#get_nth_prime(n) by subclassing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment