From: dblack@... Date: 2002-12-05T11:47:46+09:00 Subject: Re: Enumerable#map_with_indices (was Re: Conditional block operations) Hi -- On Thu, 5 Dec 2002, Paul Duncan wrote: > * David A. Black (dblack@superlink.net) wrote: > > [snipped] > > Otherwise I think you have to do some kind of pre-filtering. If we had > > map_with_indices, you could do: > > > > myarray.map_with_indices {|e,i| e + ", " if i % 2 == 0} .compact > > > > but we don't. (Hint, hint.) > > #!/usr/bin/env ruby > > module Enumerable > def map_with_indices > a = [] # should this be "self.class.new"? > each_with_index { |o, i| a << yield(o, i) } > a > end It was more a hint to Matz, though I think mwi is off the table :-) As for the self.class.new thing, I think it should be an array, since that's what #map returns. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav