Is there a method that can be used with “each” to filter array elements depending on a regular expression matching?
I have for example the following array:
arr = ["one", "has_two", "has_tree", "four"]
I want to loop into this array and to take only elements beginning with “has”.
the following code is doing the loop for all the elements
arr.each |element| do
....
end
You can use Enumerable’s
grepmethod to do this: