Created
September 17, 2015 10:52
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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