vadviktor
1/16/2017 - 3:41 PM

Ruby function using enumerator to get the multiples of a number

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)