Sha256: 8beec3288beaa94c8813b429b217b3170cd7bfd6615fab1b272df8aaee0b24e1
Contents?: true
Size: 567 Bytes
Versions: 3
Compression:
Stored size: 567 Bytes
Contents
module Enumerable # Same as #collect but with an iteration counter. # # require 'facet/enumerable/collect_with_counter' # # a = [1,2,3].collect_with_counter{ |e,i| e*i } # a #=> [0,2,6] # #-- # Why the term counter? There may be a change in Ruby 2.0 # to use this word instead of index. Index will # still be used for Array, since that is the proper meaning # in that context. In the mean time, aliases are provided. #++ def collect_with_counter r = [] each_index do |i| r << yield(self[i], i) end r end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
facets-0.7.0 | lib/facet/enumerable/collect_with_counter.rb |
facets-0.7.1 | lib/facet/enumerable/collect_with_counter.rb |
facets-0.7.2 | lib/facet/enumerable/collect_with_counter.rb |