From: Paul Brannan Date: 2001-10-06T02:46:36+09:00 Subject: [ruby-talk:22133] Re: Possible to iterate on two enumerables together? On Sat, 6 Oct 2001, Phil Mitchell wrote: > If I have two enumerables, is there a ruby way to connect them? That > is, I want to march through the two collections and operate on pairs > of items. The best I came up with was to convert each one to an array > and then iterate on the index. Yes, this is possible using a number of methods: 1) Convert the two enumerables to arrays using to_a, each, or collect, then iterator over the arrays using the [] operator and an index. 2) Use some other form of random-access to "iterate" through each enumerable. 3) Use a continuation to "continue" iteration through each enumerable. Obviously not all methods are optimal for all enumerables. Anyone know of other options? See the discussion at http://www.rubygarden.org/article.php?sid=109 regarding knu's Generator, which does exactly what you want (using continuations). Paul