"gabriele renzi" <surrender_it / remove.yahoo.it> schrieb im Newsbeitrag news:f9gha09qpp95hdmuhq498pjneu2qkqmeh1 / 4ax.com... > il Mon, 17 May 2004 13:30:49 +0200, Kristof Bastiaensen > <kristof / vleeuwen.org> ha scritto:: > > >Hi, > >I would like to know your opinion about the following idea's. > >(It is actually are two RCR's) > > > >(1)* Enumerable::filter and Enumerable::enum_filter > > > >filter([[method = :each], *args, ] block) > > yield values for which block returns true > > > >3.filter(:times, &lambda{ |i| i[0] == 0 }) do |n| > > puts "%i is even" % n > >end > >=> 2 is even > > what's wrong with > (1..3).select {|x| x[0]==0}.each {|x| p x} > ? If the Enumerable contains a huge number of elements then this version will burn a lot of memory while in certain cases (e.g. printing) it is more efficient to be able to handle one element at a time only. Well, of course in those cases you could simply do (1..3).each {|x| p x if x[0]==0} :-) Regards robert