Skip to content

Instantly share code, notes, and snippets.

@jasonnoble
Created April 20, 2010 15:07
Show Gist options
  • Save jasonnoble/372595 to your computer and use it in GitHub Desktop.
Save jasonnoble/372595 to your computer and use it in GitHub Desktop.
# 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