Ruby | Array delete_if() operation Last Updated : 13 Jan, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Array#delete_if() : delete_if() is a Array class method which deletes the arrays elements for which the block condition satisfies. Syntax: Array.delete_if() Parameter: block - condition for deleting the elements. Return: array after deleting the elements Code #1 : Example for delete_if() method Ruby # Ruby code for delete_if() method # declaring array a = [18, 22, 33, 23, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [18, 22, 12, 24, 50, 6] # delete puts "delete : #{a.delete_if{|x| x < 1}}\n\n" # delete puts "delete : #{b.delete_if{|b| b==1}}\n\n" Output : delete : [18, 22, 33, 23, 5, 6] delete : [4, 88, 9] Code #2 : Example for delete_if() method Ruby # Ruby code for delete_if() method # declaring array a = ["abc", "geeks", "dog"] # declaring array b = ["cow", "1", "dog"] # delete puts "delete : #{a.delete_if{|x| x != "dog"}}\n\n" # delete puts "delete : #{b.delete_if{|b| b=="1"}}\n\n" Output : delete : ["dog"] delete : ["cow", "dog"] Comment More infoAdvertise with us Next Article Ruby | Array at() operation M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Collections Ruby Array-class Similar Reads Ruby | Array delete() operation Array#delete() : delete() is a Array class method which returns the array after deleting the mentioned elements. It can also delete a particular element in the array. Syntax: Array.delete() Parameter: obj - specific element to delete Return: last deleted values from the array. Code #1 : Example for 2 min read Ruby | Array delete_at() operation Array#delete_at() : delete_at() is a Array class method which deletes the arrays elements at the mentioned index. Syntax: Array.delete_at() Parameter: index - value at specific index value to delete Return: deleted element, nil - if the index value is out of range Code #1 : Example for delete_at() 2 min read Ruby | Array dig() operation Array#dig() : dig() is a Array class method which extracts the specific element out of the high dimension sequences. Syntax: Array.dig() Parameter: element position. Return: element from a specific location in sequence, returning nil if any intermediate step is nil. Code #1 : Example for dig() metho 1 min read Ruby | Array at() operation Array#at() : at() is an Array class method which returns the element at the specific argumented index value. Syntax: Array.at() Parameter: - Arrays to search elements. - index to search Return: Array element at a specific index value Code #1 : Example for at() method Ruby # Ruby code for at() method 1 min read Ruby | Array collect!() operation Array#collect!() : collect!() is an Array class method which invokes the argument block once for each element of the array, replacing the element with the value returned by the block Syntax: Array.collect!() Parameter: Arrays in which we want elements to be invoked Return: array with all the envoked 1 min read Ruby | Array collect() operation Array#collect() : collect() is an Array class method which invokes the argument block once for each element of the array. A new array is returned which has the value returned by the block. Syntax: Array.collect() Parameter: Arrays in which we want elements to be invoked Return: array with all the en 1 min read Like