Printing out prime numbers from an array given a max number
Here it is using Prime#prime?:


  Suppose I want to get all the prime numbers less than 9


require 'prime'

a = (1..12).to_a
p a.select{|e| e.prime? and e &lt; 9 }
# &gt;&gt; [2, 3, 5, 7]


Here is a method

require 'prime'

def prime_below_max(a,max)
   a.select{|e| e.prime? and e &lt; max }
end

ary = (1..12).to_a
p prime_below_max(ary,9)
# &gt;&gt; [2, 3, 5, 7]