Module: Prettys::Matcher
- Defined in:
- lib/matcher.rb
Class Method Summary collapse
Class Method Details
.marked_strings(string, pattern) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/matcher.rb', line 4 def Matcher.marked_strings(string, pattern) matched = string.scan(pattern).map { |s| { string: s, marked: true } } not_matched = string.split(pattern).map { |s| { string: s, marked: false } } if (string.match(pattern).begin(0)) not_matched.zip(matched) else matched.zip(not_matched) end.flatten.compact end |