Другой вариант:
require 'prime'
def primes_smaller_than(num, res=[])
return res if num < 2
res << num if Prime.prime?(num)
primes_smaller_than(num - 1, res)
end
primes_smaller_than 100
#=> [97, 89, 83, 79, 73, 71, 67, 61, 59, 53, 47, 43, 41, 37, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2]
Чтобы распечатать его:
primes_smaller_than(100).each { |e| puts "this is prime - #{e}" }