Enumerable.reject
(or Enumerable.select
) are the correct methods to filter the sequence.
These filter methods only looks at the truthy-ness of the returned value and thus while returning i
in this case "works" (as i
is always a truthy value), the returned value is actually discarded (unlike map
) so the predicate should look more like:
c.reject {|i| !is_prime?(i)}
# or (inverting the double negative)
c.select {|i| is_prime?(i)}
# or (with &:)
c.select(&:is_prime?)
(See &:
for the magic behind the latter case.)
Also, since this is dealing with finding prime numbers, the Sieve of Eratosthenes might be a good read.