This is a common, repetitive idiom for me: filtering an array using a regular expression, and returning a sub-array. My approach doesn't seem very Ruby-like (I come from Java). I end up having many methods which look a lot like this.
What is the idiomatic Ruby way to improve this code?
def get_all_gifs(items_)
output = Array.new
filter = /.jpg$/
items_.each do |item|
next if item =~ filter
output << item
end
output
end
question from:https://stackoverflow.com/questions/17354864/ruby-filter-array-by-regex