title: find first element in array for which block returns true and return the block's return value
body: <p>I need to iterate over an array and apply a supplied block to each element, and return the first true value returned by the block, which implies that I need to stop immediately as soon as I get a true value.</p>
  
  <p>below is my code. I am a ruby newbie, and I am not sure if this code is reinventing the wheel. Maybe there is a library method or methods that can do that already? or may be this code can be simplified?</p>
  
  <pre><code>RS = {
    :x =&gt; %w(\d+ a\d+ bb\d+ ccc\d+).map{|x| /^#{x}$/},
    :y =&gt; %w(\w+ 1\w+ 22\w+ 333\w+).map{|x| /^#{x}$/}
  }.freeze
  
  def find s, t
    r = RS[s]
    if r
      r.each do |p|
        m = p.match t
        return m if m
      end
      nil
    end
  end
  
  p find :x, 'bb12345'
  </code></pre>