Method: String#split_at

Defined in:
lib/ruby/string.rb

#split_at(n) ⇒ Array(String, String)

Split the string in two at the given position

Examples:

"abc".split_at(0)   #=> ["", "abc"]
"abc".split_at(2)   #=> ["ab", "c"]

Parameters:

  • number of characters at which to split (‘n > 0`)

Returns:



54
55
56
# File 'lib/ruby/string.rb', line 54

def split_at(n)
  [take(n), drop(n)]
end