Accessing index inside map

#> [...] i cannot find something like array#each_with_index...

···

daz [mailto:dooby@d10.karoo.co.uk] wrote:

#
#David Black was once President of Citizens for MWI, Inc.
#(google "map with index" MWI).
#
#Welcome!
#
#
#You can add your own, of course.
#
#module Enumerable
# def map_with_index!
# each_with_index do |e, ix|
# self[ix] = yield e, ix
# end
# self
# end
#end
#
#arr = (1..6).to_a
#arr.map_with_index! do |e, ix|
# [2, 5].include?(ix) ? e : e*2
#end
#
#p arr
##=> [2, 4, 3, 8, 10, 6]

uber cool and simple.
Thanks daz and DavidB.

kind regards -botp

#
#
#daz
#
#
#
#