Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/extensions/array.rb

Overview

This file is part of the “Utopia Framework” project, and is licensed under the GNU AGPLv3. Copyright 2010 Samuel Williams. All rights reserved. See <utopia.rb> for licensing details.

Instance Method Summary collapse

Instance Method Details

#find_index(&block) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/utopia/extensions/array.rb', line 6

def find_index(&block)
	each_with_index do |item, index|
		if yield(item)
			return index
		end
	end
	
	return nil
end

#split_at(&block) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/utopia/extensions/array.rb', line 16

def split_at(&block)
	index = find_index(&block)
	
	if index
		return [self[0...index], self[index], self[index+1..-1]]
	end
	
	return [[], nil, []]
end