From: Robert Dober Date: 2009-06-17T08:43:19+09:00 Subject: Re: each by arity On Tue, Jun 16, 2009 at 12:33 PM, trans wrote: > > > On Jun 16, 2:10 am, Robert Klemme wrote: > >> Question is whether it is clever to duplicate all methods with another >> one that has "_slice" appended to the name.  I personally favor the >> approach with Enumerator, e.g. depending on version > > Not clever... facetious. Of course Enumerator is useful, and with 1.9 > fairly elegant. But rather, the question is why we must do > >  enum.each_slice(2).map {|a,b| ...} > > when > >  enum.map {|a,b| ...} > > could be made to work. This is especially interesting b/c it seems the > underlying implementation stands to be simpler and faster by doing so. That is intriguing and I am surprised. However, why should enum.map{ |a,b| } have the semantics of enum.each_slice( 2 ).... and not enum.each_cons( 2 ).... ? Maybe we need to push the abstraction even higher. Hopefully you understand what that sentence means, because I do not, but it felt just right to write it. Strange, strange. Now I am not so fond of enumerator, because it is really crazy. x=%w{a b c d} y = x.enum_for( :rand ) y.each do | a | p a end => 0.680141319345242 Do you agree with me that enum_for should use #public_send instead of #send? Cheers Robert Cheers Robert > > T. > > > -- Toutes les grandes personnes ont d’abord été des enfants, mais peu d’entre elles s’en souviennent. All adults have been children first, but not many remember. [Antoine de Saint-Exupéry]