Sha256: 48253651176aae3ccc54caab97c90d53da5ec0419f972ad73226821931ee33c4

Contents?: true

Size: 551 Bytes

Versions: 1

Compression:

Stored size: 551 Bytes

Contents

module RegexpExamples
  class BackReferenceTracker
    @filled_groups = {}
    class << self
      attr_accessor :filled_groups

      def add_filled_group(num, group)
        @filled_groups[num] = group
      end
    end
  end

  class BackReferenceReplacer
    def substitute_backreferences(full_example)
      # TODO: Update this for named capture groups
      # TODO: Define this magic __X__ pattern as a constant? Maybe?
      full_example.gsub!(/__(\d+)__/) do |_|
        BackReferenceTracker.filled_groups[$1.to_i]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
regexp-examples-0.0.0 lib/regexp-examples/backreferences.rb