Pass code block into each
require 'mathn' primes = Prime.new primes.each { |x| puts x; break if x > 15; } # 5 # 7 # 11 # 13 # 17 primes.succ # => 19