Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
Created September 17, 2015 10:52
Show Gist options
  • Save emad-elsaid/6baf32576e35a5061a8f to your computer and use it in GitHub Desktop.
Save emad-elsaid/6baf32576e35a5061a8f to your computer and use it in GitHub Desktop.
works like index for string but return all indices occurrences for a substring
class String
def indices(part)
ids = []
begin
ids << index(part, (ids[-1]||-1)+1)
end while !ids[-1].nil?
ids.pop
ids
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment