Method: Array#split_at

Defined in:
lib/ruby/array.rb

#split_at(n) ⇒ (Array, Array)

Split the array in two at the given position.

Examples:

[1, 2, 3].split_at(2)   #=> [[1,2], [3]]
[1, 2, 3].split_at(0)   #=> [[], [1,2,3]]

Returns:



85
86
87
88
# File 'lib/ruby/array.rb', line 85

def split_at(n)
  n = length + n if n < 0
  return take(n), drop(n)
end