Created
March 3, 2014 11:28
-
-
Save apeiros/9323149 to your computer and use it in GitHub Desktop.
This file contains 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 match_all(regex) | |
if block_given? | |
scan(regex) { yield $~ } | |
else | |
enum_for(:scan, regex).map { $~ } | |
end | |
end | |
end | |
# ALTERNATIVE implementation | |
# matches = [] | |
# scan(regex) do matches << $~ end | |
# matches |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment