Sha256: 7f80f5f206e93abee33840afe201cb8d2d2954b9a7e40edc19a31d0a871ce42d
Contents?: true
Size: 832 Bytes
Versions: 1
Compression:
Stored size: 832 Bytes
Contents
class Arugula class MatchData def initialize(regexp, string) # require "awesome_print" # ap regexp, raw: true @regexp = regexp @string = string.dup.freeze @captures = Hash[regexp.captures.map { |c| [c.name, nil] }] end def add_capture(name, start_index, end_index) @captures[name] = start_index...end_index end attr_accessor :start_index attr_accessor :end_index def to_s @string[start_index...end_index] end def inspect captures_part = @captures.map do |name, range| " #{name}:#{@string[range].dump}" end.join "#<MatchData #{to_s.dump}#{captures_part}>" end def to_a @captures.map { |_name, range| @string[range] }.unshift(to_s) end def freeze @captures.freeze super end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
arugula-0.3.0 | lib/arugula/match_data.rb |