lib/g5k/enumerable_extensions.rb in cryx-g5k-0.2.7 vs lib/g5k/enumerable_extensions.rb in cryx-g5k-0.2.8
- old
+ new
@@ -1,9 +1,11 @@
# for versions of ruby < 1.8.7
module Enumerable
def index_by
inject({}) do |accum, elem|
- accum[yield(elem)] = elem
+ key = yield(elem)
+ accum[key] ||= []
+ accum[key] << elem
accum
end
end
def group_by #:yield:
\ No newline at end of file