Peña, Botp
7/8/2005 9:13:00 AM
daz [mailto:dooby@d10.karoo.co.uk] wrote:
#> [...] i cannot find something like array#each_with_index...
#
#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
#
#
#
#