Skip to content

Instantly share code, notes, and snippets.

@texel
Created March 1, 2012 16:17
Show Gist options
  • Save texel/92705bacd37adbf9dd51 to your computer and use it in GitHub Desktop.
Save texel/92705bacd37adbf9dd51 to your computer and use it in GitHub Desktop.
def block_find(&block)
each do |i|
result = yield i
return result if result
end
end
>> %w(foo bar baz).block_find { |s| s.match(/(o)/) }
=> #<MatchData "o" 1:"o">
@judofyr
Copy link

judofyr commented Mar 1, 2012

def block_find(&block)
  each do |i|
    return yield(i) || next
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment