n } Enumerator.new(a).each { |n| puts n } naturals = Enumerator.new do |y| n = 1 loop do y << n n += 1 end end odds = Enumerator.new do |y| naturals.each do |n| y << n if n % 2 != 0 end end class Integer def prime? return false if self < 2 max = Math.sqrt(self).floor (2..max).none? { |n| self % n == 0 } end end primes = Enumerator.new do |y| y << 2 odds.each do |n| y << n if n.prime? end end puts primes.take(10).inspect # => [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]