Method: String#before

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

#before(delimiter) ⇒ String

Searches for the first occurrence of delimiter, and returns the portion of the String before that. If delimiter is not found, returns a copy of the original String. Equivalent to split(delimiter, 2)[0] for non-empty delimiters.

Examples:

"http://www.example.com".before("://")  # == "http"
"http://www.example.com".before("?")    # == "http://www.example.com"
"http://www.example.com".before("")     # == ""

Parameters:

Returns:



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

def before(delimiter)
  self[0, self.index(delimiter) || self.length]
end