In Ruby, you can use methods like `reject` or `delete_if` to remove elements from an array based on a condition.
In this example,
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
filtered_numbers = numbers.reject { |num| num.odd? }
puts 'Array after filtering:'
puts filtered_numbers
Array after filtering: 2 4 6 8 10
In this example,
words = ['apple', 'banana', 'grape', 'orange', 'melon']
filtered_words = words.reject { |word| word.include?('a') }
puts 'Array after filtering:'
puts filtered_words
Array after filtering: melon
In this tutorial, we learned How to Remove Element from Array based on a Condition in Ruby language with well detailed examples.