Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/codemodels/html/monkey_patching.rb

Instance Method Summary collapse

Instance Method Details

#first_index(sub) ⇒ Object



3
4
5
6
7
8
# File 'lib/codemodels/html/monkey_patching.rb', line 3

def first_index(sub)
	(0..(self.length-1)).each do |i|
		return i if self[i,sub.length].start_with?(sub)
	end
	nil
end

#last_index(sub) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/codemodels/html/monkey_patching.rb', line 10

def last_index(sub)
	last = nil
	(0..(self.length-1)).each do |i|
		last=i if self[i,sub.length].start_with?(sub)
	end
	last
end