Method: String#after_last

Defined in:
lib/casual_support/string/after_last.rb

#after_last(delimiter) ⇒ String?

Searches for the last occurrence of delimiter, and returns the portion of the String after that. If delimiter is not found, returns nil. Equivalent to split(delimiter, -1).drop(1)[-1] for non-empty delimiters.

Examples:

"/path/to/file".after_last("/")  # == "file"
"/path/to/file".after_last(".")  # == nil
"/path/to/file".after_last("")   # == ""

Parameters:

Returns:



15
16
17
18
# File 'lib/casual_support/string/after_last.rb', line 15

def after_last(delimiter)
  i = self.rindex(delimiter)
  i && self[i + delimiter.length, self.length]
end