Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/6510
Created by Marc-André Lafortune - 2011-03-03 05:11:39 UTC
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:
foo = [nil, nil]
Imported from Lighthouse.
Comment by Jeff Kreeftmeijer - 2011-03-06 09:16:05 UTC
I cleaned up your ticket a bit. Please be sure to wrap inline code in backticks, since starting a line with a # will turn it into a header. :)
Attachments saved to Gist: http://gist.github.com/971798