If array = [1, 2, 3, 4, 5, 6, 7, 8, 9], I want to delete a range of elements from array.
array = [1, 2, 3, 4, 5, 6, 7, 8, 9]
For example: I want to delete all elements with an index in th
As Stefan posted, use slice! to remove values located inside a certain range in the array. If what you need, however, is to remove values that are within a certain range use delete_if.
slice!
delete_if
array = [9, 8, 7, 6, 5, 4, 3, 2, 1] array.delete_if {|value| (2..5) === value } array #=> [9, 8, 7, 6, 1]