This is because everyone uses an enumerator (so it never reaches the end if you keep adding to it).
You can duplicate an array before applying each of them.
nums = [1, 2, 3] nums.dup.each { |i| nums << i + 1 }
Another way is to add additional elements defined by the map:
nums = [1, 2, 3] nums += nums.map { |i| i + 1 }
source share