From: dblack@... Date: 2002-11-27T04:02:23+09:00 Subject: Re: each_with_index & collect_with_index? Hi -- On Wed, 27 Nov 2002, ahoward wrote: > On Wed, 27 Nov 2002 dblack@candle.superlink.net wrote: > > [snip] > D> It could get unclean in a hurry, though :-) > D> > D> class Thing < Array > D> def meth(other) > D> a = collect { |e| do_something_with(e) } > D> b = collect_with_index(self,other)... # ugh > D> ... > D> end > D> end > [snip] > > i'm unclear as to what you mean : > > a = collect { |e| do_something_with(e) } > > this would be Array#collect, what does it have to do with the following line? > > b = collect_with_index(self,other)... > > i don't really understand to point of the example. > > and why 'ugh'? you have to have, at minimum, one method name and a name for > each Enumerable in the argument list : how could it get any > moresuccinct than that? if you have a better suggestion i can > incorporate it and post it... What I don't like is the idea that #collect and #collect_with_index behave so differently: one being an iterator instance method, the other a kind of utility/batch-iterator. > on second thought i would like to retract earlier statements about those > methods belonging in Kernel (what was i thinking ) and say those methods > should go in Enumerable as module methods so the above would need be > > b = Enumerable.collect_with_index(self,other)... > > i've updated > > http://eli.fsl.noaa.gov/lib/ruby/site_ruby/1.6/enumerable.rb > > to reflect this. > > i think we may be at cross-purposes : what i'm suggesting are methods which > operate over n Enumerable items in synchronicity - not instance methods to be > inherited by classes mixing in Enumerable... was this clear? We're not at cross purposes -- that is, I understood what you meant. I just disagree :-) I think collect_with_index belongs among the instance method of enumerables, just like collect, each, and each_with_index. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav