Created
December 17, 2012 05:37
-
-
Save nixpulvis/4316018 to your computer and use it in GitHub Desktop.
get_if for arrays.
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 | |
# Return the first element where the given block returns true for. | |
def get_if | |
each { |v| return v if yield v } | |
return false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment