From: Jari Williamsson Date: 2007-11-30T20:51:20+09:00 Subject: Delete array element within iterator block? How do I (in an elegant way) delete an element of an array within a block, while using a block iterator? The code below won't work (the wanted behavior here is to get all array elements to print and but also delete the 2nd element after it has been encountered): --- arr = [1,2,3,4] arr.each_with_index { |e, i| p e arr.delete_at(i) if i == 1 } --- results in: 1 2 4 Of curse, I could loop and keep track of the index manually, but I'm mainly checking if there is any built-in stuff here. Best regards, Jari Williamsson