From: David Alan Black Date: 2000-12-13T05:36:02+09:00 Subject: [ruby-talk:7108] "map_with_indices" and related musings Hello -- So many recent discussions here of Array (and/or Enumerable) methods seem to involve arrays knowing how to do things with other arrays, generally in exact alternation: interleaving, hashing themselves against their own indices, getting iterated over at the same time.... Well, here's another. I reproduce it here because I've found it useful, am curious whether other people have invented something similar, and wonder whether there's a more streamlined way to do it. Also... well, here it is, first: class Array def map_with_indices res = [] each_with_index do |e,i| res.push yield e,i end res end end ...to continue, re: Array enhancements: I wonder whether there's some unifying, underlying Thing that all these problems we're solving are mutually doing. If so, what exactly is that Thing (interleaving with self's indices?) and can the cluster of methods we've been talking about (interleaving, to_hashing, etc.) be factored and constructed, as a group, to reflect that unity? David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav