Last active
December 16, 2015 13:59
-
-
Save entrity/5445458 to your computer and use it in GitHub Desktop.
Ruby: Returns the first matching object in an Array, without iterating all the way through as #select does and without having to first return an index as #index does.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def search(&block) | |
self.each do |item| | |
break item if block.call(item) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment