#!/usr/bin/ruby module Enumerable def map_with_indices a = [] # should this be self.class.new ? each_with_index { |o, i| a << yield(o, i) } a end # for those unfamiliar with the nuances of the english language alias_method :map_with_indexes, :map_with_indices end if __FILE__ == $0 # test arrays a = [1, 1, 2, 3, 5, 8, 13, 21] puts 'a:', a, 'a.map_with_indices:', a.map_with_indices { |o, i| o + i } end