# File lib/facet/string/last.rb, line 18 def last(n=1, pattern='') pattern = '' if pattern == // case pattern when '' return slice(-n, n) # RETURNS when "\n" pattern = /\n+|\Z/ when nil pattern = /\s+|\Z/ when String pattern = Regexp.new( Regexp.escape( separator ) ) #if String === separator end rself = self.reverse i,s,e = 0,0,0 n.times { i = rself.index( pattern, s ) break unless i e = i s = $~.end(0) } rself.slice(0...e).reverse end