Skip to content

Instantly share code, notes, and snippets.

@ethicalhack3r
Created July 12, 2013 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethicalhack3r/5982734 to your computer and use it in GitHub Desktop.
Save ethicalhack3r/5982734 to your computer and use it in GitHub Desktop.
The array size decreases on delete, however, the 'internal loop counter' stays the same.
a=[1,2,3,4]; a.each_with_index{|e,i| p "Iteration #{i}: delete #{e} - size of array #{a.size}"; a.delete(e) }
"Iteration 0: delete 1 - size of array 4"
"Iteration 1: delete 3 - size of array 3"
=> [2, 4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment