class Vernacular::RegexModifier

Represents a modification to Ruby source that should be injected into the require process that modifies the source via a regex pattern.

Attributes

block[R]
pattern[R]
replacement[R]

Public Class Methods

new(pattern, replacement = nil, &block) click to toggle source
# File lib/vernacular/regex_modifier.rb, line 9
def initialize(pattern, replacement = nil, &block)
  @pattern = pattern
  @replacement = replacement
  @block = block
end

Public Instance Methods

components() click to toggle source
# File lib/vernacular/regex_modifier.rb, line 23
def components
  [pattern, replacement] + (block ? block.source_location : [])
end
modify(source) click to toggle source
# File lib/vernacular/regex_modifier.rb, line 15
def modify(source)
  if replacement
    source.gsub(pattern, replacement)
  else
    source.gsub(pattern, &block)
  end
end