How does Ruby enumerator terminate iteration?
问题 Friends, please I need help with this explanation: In the Ruby code below, what condition termites the loop do? It's supposed to be an infinite loop, but, how does it terminate? # Ruby code fib = Enumerator.new do |y| a = b = 1 loop do y << a a, b = b, a + b end end p fib.take(10) # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] Your contributions will be highly appreciated. 回答1: (Source: https://rossta.net/blog/infinite-sequences-in-ruby.html) The way you have implemented the function fib allows it