Created
December 4, 2008 23:12
-
-
Save webmat/32138 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 String | |
# Return everything after the given string | |
# or nil if the substring can't be found | |
def after(prefix) | |
match = self.match Regexp.new(Regexp.escape(prefix) + "(.*)") | |
match && match[1] | |
end | |
end | |
dir = "/Users/mat/Desktop/wordpress-1" | |
#=> "/Users/mat/Desktop/wordpress-1" | |
file = "/Users/mat/Desktop/wordpress-1/wp-trackback.php" | |
#=> "/Users/mat/Desktop/wordpress-1/wp-trackback.php" | |
file.after dir | |
#=> "/wp-trackback.php" | |
file.after "uhh" | |
#=> nil | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment