How to modify the implementation of the map function in the Array class in Ruby

Is there a way to modify the implementation of map() in the Array class such that it only affects certain indices of the array?

Example:

a = [1, 2, 3, 4, 5]
a.map(2..4) { |x| x*2 }

Now, a = [1, 2, 6, 8, 10] since the map function was only used on indices 2 and 3.



Read more here: https://stackoverflow.com/questions/64380605/how-to-modify-the-implementation-of-the-map-function-in-the-array-class-in-ruby

Content Attribution

This content was originally published by FromTheEast at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: