module RubbyCop::Cop::MatchRange
Common functionality for obtaining source ranges from regexp matches
Public Instance Methods
each_match_range(range, regex) { |match_range(range, last_match)| ... }
click to toggle source
Return a new `Range` covering the first matching group number for each match of `regex` inside `range`
# File lib/rubbycop/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)
click to toggle source
For a `match` inside `range`, return a new `Range` covering the match
# File lib/rubbycop/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