 <p>If you study the following simplified example you will understand why deleting elements of the array over which you are iterating caused the result you obtained.</p> <pre><code>s = "two lions" s = s.split("") puts "s.split=#{s}" for i in 0..s.length - 1 do puts "i=#{i}" str = s[i] puts " str=/#{str}/" if ["a","e","i","o","u"].include?(s[i]) puts " str is a vowel" s.delete_at(i) puts " s after delete_at(#{i})=#{s}" end end puts "s after loop=#{s}" puts "s.join=#{s.join}" s.join </code></pre> <p>prints</p> <pre><code>s.split=["t", "w", "o", " ", "l", "i", "o", "n", "s"] i=0 str=/t/ i=1 str=/w/ i=2 str=/o/ str is a vowel s after delete_at(2)=["t", "w", " ", "l", "i", "o", "n", "s"] </code></pre> <p>The space is skipped.</p> <pre><code>i=3 str=/l/ i=4 str=/i/ str is a vowel s after delete_at(4)=["t", "w", " ", "l", "o", "n", "s"] </code></pre> <p>"o" is now at index 4 and "n" is at index 5.</p> <pre><code>i=5 str=/n/ i=6 str=/s/ i=7 str=// i=8 str=// s after loop=["t", "w", " ", "l", "o", "n", "s"] s.join=tw lons </code></pre>