UtopiaSourceUtopiaExtensionsArraySplit

module ArraySplit

Adds splitting helpers to arrays.

Definitions

def split_at(*arguments, &block)

Split the array around the first element matching the arguments or block.

Signature

parameter arguments Array

The arguments accepted by Array#index.

yields {|element| ...}

Each element until the block matches.

returns Array(Array, Object, Array)

The elements before the match, the matching element, and the elements after it; the middle value is nil when no element matches.

Implementation

def split_at(*arguments, &block)
	if middle = index(*arguments, &block)
		[self[0...middle], self[middle], self[middle+1..-1]]
	else
		[[], nil, []]
	end
end