From: Wilson Bilkovich Date: 2007-09-08T03:08:01+09:00 Subject: Re: New array methods cycle, choice, shuffle (plus bug in cycle) On 9/7/07, Urabe Shyouhei wrote: > Wilson Bilkovich wrote: > > Could someone explain the Array#cycle / Enumerable#cycle use case to me? > > I'm not seeing it. > > fizz = ['Fizz', '', ''].cycle > buzz = ['buzz', '', '', '', ''].cycle > fizzbuzz = fizz.zip buzz > > fizzbuzz.each_with_index do |i, j| > k = i.join > puts k.empty? ? j : k > end > So the above code is expected to behave as this would in Ruby 1.8? fizz = ['Fizz', '', ''] buzz = ['buzz', '', '', '', ''] fizzbuzz = fizz.zip buzz count = 0 loop do fizzbuzz.each do |i| k = i.join puts k.empty? ? count : k count += 1 end end ..or does zipping an external enumerator with 'more' entries operate differently than zipping the two Arrays?