I got burned by the fact that Enumerable#index_by
does not return an Enumerator if called without block, so I took a
moment to fix the issues I could find in the enumerable extension,
namely:
#index_by, #group_by and
#each_with_object now return Enumerators as they
should.
#many? iterates only as much as needed to determine
the result. It also doesn't rely on #size (which not
all Enuemrables respond to).
The patch also improves the robustness of the tests.
#each_with_object is also optimized by not capturing
the block.
Problems not addressed:
* most extensions assume that the Enumerable yields only one
argument. * the definition of #many? can be confusing
because the form without block doesn't test for truthiness. Thus
foo.many? is not necessarily equal to
foo.many?{|x| x}, and foo.any? can be
false while foo.many? can be true (e.g. foo = [nil,
nil]). Discounting nil/false would be ideal, except that it
could break compatibility, so I leave this up to the powers that
be.
Thanks!
Marc-André