Class: Array

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

Instance Method Summary collapse

Instance Method Details

#find_index(&block) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/utopia/extensions.rb', line 60

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

#split_at(&block) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/utopia/extensions.rb', line 70

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