Search a value across 2 array I want to find the corresponding hash in an array from a string that contains a criterion defined in a hash of the array.

I do something like that :

types = [
 {key: 'type_1', criteria: ['type_1a', 'type_1b']},
 {key: 'type_2', criteria: ['type_2a', 'type_2b']},
 ...
]

def find_type(str)
  types.each do |type|
    type[:criteria].each do |criterion|
      return type if str =~ /#{criterion}/i
    end
  end
  nil
end


I'm sure it could be more ruby but don't find how...
The orthodox (and functional) approach in Ruby is:

def find_type(types, str)
  types.detect do |type|
    type[:criteria].any? do |criterion|
      str =~ /#{criterion}/i # or Regexp.new(criterion, "i")
    end
  end
end