title: Return a single value from a nested each block, trying to use 'return'
body: <pre><code>def get_type
    x = [{:type=&gt;'A', :patterns=&gt;['foo.*']}, {:type=&gt;'B', :patterns=&gt;['bar.*']}]
  
    name = 'foo.txt'
  
    result = x.each { |item|
      item[:patterns].each { |regex|
        puts "Checking #{regex} against #{name}"
        if !name.match(regex).nil?
          puts "Found match: #{item[:type]}"
          return item[:type]
        end
      }
    }
  end
  
  result = get_type
  puts "result: #{result}"
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre><code>Checking foo.* against foo.txt
  Found match: A
  result: A
  </code></pre>
  
  <p>However, all I see is:</p>
  
  <pre><code>Checking foo.* against foo.txt
  Found match: A
  </code></pre>
  
  <p>My current work around is this:</p>
  
  <pre><code>def get_type
    x = [{:type=&gt;'A', :patterns=&gt;['foo.*']}, {:type=&gt;'B', :patterns=&gt;['bar.*']}]
  
    name = 'foo.txt'
  
    result = []
    x.each { |item|
      item[:patterns].each { |regex|
        puts "Checking #{regex} against #{name}"
        if !name.match(regex).nil?
          puts "Found match: #{item[:type]}"
          result &lt;&lt; item[:type]
        end
      }
    }
    result[0] unless result.empty?
  end
  </code></pre>
  
  <p>Why doesn't the first approach work? or maybe it is 'working', I just don't understand why I'm not getting what I'd expect.</p>