webmat (owner)

Revisions

gist: 32138 Download_button fork
public
Public Clone URL: git://gist.github.com/32138.git
Embed All Files: show embed
String#after.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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