Module: Index_All::String

Included in:
String
Defined in:
lib/mightystring/string_index_all.rb

Instance Method Summary collapse

Instance Method Details

#index_all(in_srch = "") ⇒ Object

find_all(search string): Returns indexes of search string as an index array.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mightystring/string_index_all.rb', line 9

def index_all(in_srch = "")
  in_srch = in_srch.to_s
  if not in_srch.empty?
    arr_indexes = []
    srch_index = self.rindex(in_srch)
    while not srch_index.nil? do
      tmpStr = self[0..srch_index-1]
      arr_indexes += [srch_index] # Put it in the list
      if srch_index == 0
        srch_index = nil
      else
        srch_index = tmpStr.rindex(in_srch)
      end
    end
    return arr_indexes.reverse
  end
end