I am trying to delete all elements from an array. For example:
@array = [1,2,3,4,5]
@array.each do |element|
@array.delete(element)
end
Now, I understand why the code above does not work. However, I am tasked with deleting all elements of an array while using this delete_entry
method:
def delete_entry(entry)
@array.delete(entry)
end
I have read that removing elements in the midst of iteration is disallowed by design in ruby. Any ideas as to how I would go about deleting all elements from an array while using the delete_entry
method in my implementation?