From: Paul Brannan Date: 2001-11-15T00:06:09+09:00 Subject: [ruby-talk:25187] Re: Parallel array iteration One option is, of course, using an index to iterate over the array. Another option is an "external iterator" that has at least two methods: 1) get the current element, 2) advance to the next element. There are a number of implementations of external iterators out there; some of them convert the container to an array and then iterate over the array, while others use a continuation to keep state while iterating. There was some discussion on the Rubygarden about knu's external iterators at: http://www.rubygarden.org/article.php?sid=107 Also be sure to read the FAQ at: http://www.rubycentral.com/faq/rubyfaq-5.html#ss5.5 Horst Duchene has written a set of external iterators that he calls "streams": http://www.ruby-lang.org/en/raa-list.rhtml?name=stream.rb My personal favorite is what I call a "buffered continuation iterator": http://rm-f.net/~cout/ruby/treasures/RubyTreasures-0.1/lib/iterator/buffered_continuation_iterator.rb Paul On Wed, 14 Nov 2001, Jim Freeze wrote: > Hi > > I've got a block here...It seems that I have seen that > Ruby can do iteration over multiple arrays, but I have > not been able to find it. For example, I would like > to do something like the following: > > a=%w{a b c} > b=[1,2,3] > > for x,y in a,b > puts "#{x},#{y}" > end > > a,1 > b,2 > c,3 > > > Or even better yet, do the above without the 'for'. > Yes, I can do this with each_index, but I would like to avoid > de-indexing if I don't have to. > > Thanks > > > > ========================================================= > Jim Freeze > jim@freeze.org > --------------------------------------------------------- > Today is a fine day for Ruby programming. > http://www.freeze.org > ========================================================= >