Class: MatchData

Inherits:
Object show all
Defined in:
lib/backports/3.1.0/match_data/match.rb,
lib/backports/3.2.0/match_data/byteoffset.rb,
lib/backports/3.1.0/match_data/match_length.rb,
lib/backports/3.3.0/match_data/named_captures.rb

Instance Method Summary collapse

Instance Method Details

#byteoffset(n) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/backports/3.2.0/match_data/byteoffset.rb', line 3

def byteoffset(n)
  if (char_start_offset = self.begin(n))
    char_end_offset = self.end(n)
    [string[0, char_start_offset].bytesize, string[0, char_end_offset].bytesize]
  else
    [nil, nil]
  end
end

#match(index) ⇒ Object



2
3
4
# File 'lib/backports/3.1.0/match_data/match.rb', line 2

def match(index)
  self[index]
end

#match_length(index) ⇒ Object



2
3
4
5
# File 'lib/backports/3.1.0/match_data/match_length.rb', line 2

def match_length(index)
  m = self[index]
  m && m.length
end

#named_captures_with_symbolize_option(symbolize_keys: false) ⇒ Object



5
6
7
8
9
# File 'lib/backports/3.3.0/match_data/named_captures.rb', line 5

def named_captures_with_symbolize_option(symbolize_keys: false)
  captures = named_captures_without_symbolize_option
  captures.transform_keys!(&:to_sym) if symbolize_keys
  captures
end