From: ES Date: 2005-10-19T13:42:42+09:00 Subject: Re: Unit testing an each function ES wrote: > Kevin Ballard wrote: > >> James Edward Gray II wrote: >> >>> Hmm, isn't what you wrote an automatic Generator class? (See >>> standard library.) >> >> >> >> Not really. Generator basically gives you external iterators which you >> can access element by element, so you can do things like iterate over 2 >> enumerables in step. What I wrote is basically just a convenience for >> applying a method call to all the elements in a single enumerable. >> After all, >> >> %w{a long list of words}.collect.length >> >> is the same thing as >> >> %w{a long list of words}.collect { |item| item.length} >> >> but easier to read. >> >> >>> Yeah, I don't have a problem with it. I'm probably not the kind of >>> guy who would using it, but if you and others would, go for it. I >>> love sharing. :) >> >> >> >> Ok, then I'll probably package it up tomorrow. > > > Please do! This idiom is an improvement over dbrock's foo.each {.succ} > which still required a preprocessor. Whoops, sent too soon! I was going to continue to say that while this is nice, for clarity of expression you might want to state it this way: %w{a long list of words}.collect :length E