需要有关循环的帮助

bra*_*boy 1 ruby loops

我需要这种模式的循环.我需要一个无限循环,产生以1开头的数字.

1,10,11,12..19,100,101,102..199,1000,1001.......
Run Code Online (Sandbox Code Playgroud)

sep*_*p2k 5

def numbers_that_start_with_1
  return enum_for(:numbers_that_start_with_1) unless block_given?

  infty = 1.0 / 0.0
  (0..infty).each do |i|
    (0 .. 10**i - 1).each do |j|
      yield(10**i + j)
    end
  end
end

numbers_that_start_with_1.first(20)
#=>  [1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 100, 101, 102, 103, 104, 105, 106, 107, 108]
Run Code Online (Sandbox Code Playgroud)