Module: RuboCop::Cop::MatchRange

Included in:
Style::SpaceInsideArrayPercentLiteral, Style::SpaceInsidePercentLiteralDelimiters
Defined in:
lib/rubocop/cop/mixin/match_range.rb

Overview

Common functionality for obtaining source ranges from regexp matches

Instance Method Summary collapse

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`



10
11
12
13
14
# File 'lib/rubocop/cop/mixin/match_range.rb', line 10

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



17
18
19
20
21
22
23
# File 'lib/rubocop/cop/mixin/match_range.rb', line 17

def match_range(range, match)
  Parser::Source::Range.new(
    range.source_buffer,
    range.begin_pos + match.begin(1),
    range.begin_pos + match.end(1)
  )
end