Sha256: ae83a6286935771750a848b9fd0693d67fa9af5e69190d61cddbe75db02d3b24

Contents?: true

Size: 466 Bytes

Versions: 4

Compression:

Stored size: 466 Bytes

Contents

class String
  # Like index but returns an array of all index locations.
  # The reuse flag allows the trailing portion of a match to be 
  # reused for subsquent matches.
  #
  #   require 'facet/string/index_all'
  #
  #   "abcabcabc".index_all('a')  #=> [0,3,6]
  #
  def index_all(s, reuse=false)
    ia = []; i = 0
    while (i = self.index(s,i))
      ia << i
      i += (reuse ? 1 : $~.length)
    end
    ia
  end
  #alias_method( :indexes, :index_all )
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
facets-0.6.3 lib/facet/string/index_all.rb
facets-0.7.0 lib/facet/string/index_all.rb
facets-0.7.1 lib/facet/string/index_all.rb
facets-0.7.2 lib/facet/string/index_all.rb