Sha256: ee82622f1b749e6c39a525ea5328f665415e634f897a971db3d766b1d4f71b7e
Contents?: true
Size: 595 Bytes
Versions: 15
Compression:
Stored size: 595 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. # # "abcabcabc".index_all('a') #=> [0,3,6] # # "bbb".index_all('bb', false) #=> [0] # "bbb".index_all('bb', true) #=> [0,1] # # TODO: Culd probably be defined for Indexable in general too. def index_all(s, reuse=false) s = Regexp.new(Regexp.escape(s)) unless Regexp===s ia = []; i = 0 while (i = index(s,i)) ia << i i += (reuse ? 1 : $~[0].size) end ia end end
Version data entries
15 entries across 14 versions & 2 rubygems