class Fixnum
def primes
range = []
circled = []
count = 2 # counter
# populate range with all integers from 2 to self
(count..self).each {|i| range << i}
range.reject!{|n| n%2==0} # get rid of even numbers
stop = Math::sqrt(self).round # last multiple to try
circled << 2 # circle first prime number
while count <= self
break if range[0]==stop or range[0]==nil
circled << range.first
range.reject!{|n| n%circled.last==0}
count += 1
end
circled
end
end