Sha256: 3428a4bb130e2acf9e2e59e7951bc1def6be25e09a69241f67cb0b7f5b42e804

Contents?: true

Size: 374 Bytes

Versions: 13

Compression:

Stored size: 374 Bytes

Contents

module Enumerable

  # Same as #collect but with an iteration counter.
  #
  #   a = [1,2,3].collect_with_index { |e,i| e*i }
  #   a  #=> [0,2,6]
  #
  # CREDIT: Gavin Sinclair

  def map_with_index
    r = []
    each_with_index do |e, i|
      r << yield(e, i)
    end
    r
  end

  # Alias for map_with_index.

  alias_method :collect_with_index, :map_with_index

end

Version data entries

13 entries across 12 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/enumerable/map_with_index.rb
facets-3.1.0 lib/core/facets/enumerable/map_with_index.rb
facets-3.0.0 lib/core/facets/enumerable/map_with_index.rb
facets-2.9.3 lib/core/facets/enumerable/map_with_index.rb
facets-2.9.2 lib/core/facets/enumerable/map_with_index.rb
facets-2.9.2 src/core/facets/enumerable/map_with_index.rb
facets-2.9.1 lib/core/facets/enumerable/map_with_index.rb
facets-2.9.0 lib/core/facets/enumerable/map_with_index.rb
facets-2.9.0.pre.2 lib/core/facets/enumerable/map_with_index.rb
facets-2.9.0.pre.1 lib/core/facets/enumerable/map_with_index.rb
facets-2.8.4 lib/core/facets/enumerable/map_with_index.rb
facets-2.8.3 lib/core/facets/enumerable/map_with_index.rb
facets-2.8.2 lib/core/facets/enumerable/map_with_index.rb