Sha256: ea5aa51b323ac1d1b2954dc1bf0188bcbae244d1b28f8c42d9aab0c2985c9f16

Contents?: true

Size: 977 Bytes

Versions: 1

Compression:

Stored size: 977 Bytes

Contents

module CoreExtensions
  module Regexp
    # A wrapper module to namespace/isolate the Regexp#examples and Regexp#random_example
    # monkey patches.
    # No core classes are extended in any way, other than the above two methods.
    module Examples
      def examples(**config_options)
        RegexpExamples::Config.with_configuration(**config_options) do
          examples_by_method(:result)
        end
      end

      def random_example(**config_options)
        RegexpExamples::Config.with_configuration(**config_options) do
          examples_by_method(:random_result).sample
        end
      end

      private

      def examples_by_method(method)
        full_examples = RegexpExamples.generic_map_result(
          RegexpExamples::Parser.new(source, options).parse,
          method
        )
        RegexpExamples::BackReferenceReplacer.new.substitute_backreferences(full_examples)
      end
    end
  end
end

Regexp.include(CoreExtensions::Regexp::Examples)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
regexp-examples-1.5.1 lib/core_extensions/regexp/examples.rb