Module: RuboCop::Cop::MatchRange
- Defined in:
- lib/rubocop/cop/mixin/match_range.rb
Overview
Common functionality for obtaining source ranges from regexp matches
Instance Method Summary collapse
-
#each_match_range(range, regex) ⇒ Object
Return a new
Rangecovering the first matching group number for each match ofregexinsiderange. -
#match_range(range, match) ⇒ Object
For a
matchinsiderange, return a newRangecovering the match.
Instance Method Details
#each_match_range(range, regex) ⇒ Object
Return a new Range covering the first matching group number for each match of regex inside range
9 10 11 12 13 |
# File 'lib/rubocop/cop/mixin/match_range.rb', line 9 def each_match_range(range, regex) range.source.scan(regex) do yield match_range(range, Regexp.last_match) end end |
#match_range(range, match) ⇒ Object
For a match inside range, return a new Range covering the match
16 17 18 19 |
# File 'lib/rubocop/cop/mixin/match_range.rb', line 16 def match_range(range, match) range_between(range.begin_pos + match.begin(1), range.begin_pos + match.end(1)) end |