Created
April 20, 2010 15:07
-
-
Save jasonnoble/372595 to your computer and use it in GitHub Desktop.
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
# Usage: | |
# Returns the index of the first element of the array | |
# that matches the regular expression provided | |
# | |
# lines.index_regex(/\d{4}\-\d{2}\-\d{2}/) | |
# | |
class Array | |
def index_regex(pattern) | |
self.each_with_index do |value,index| | |
return index if pattern.match(value) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment