Ruby function using enumerator to get the multiples of a number
require 'pp' def multiples_of(n) i = n Enumerator.new do |y| loop do y << i i += n end end end pp multiples_of(3).take(5)