# class Puppet::Parser::AST::Regex

### Public Class Methods

new(hash) click to toggle source
Calls superclass method

    # File lib/puppet/parser/ast/leaf.rb, line 176
    def initialize(hash)
      super
      @value = Regexp.new(@value) unless @value.is_a?(Regexp)
    end

### Public Instance Methods

evaluate(scope) click to toggle source

we’re returning self here to wrap the regexp and to be used in places where a string would have been used, without modifying any client code. For instance, in many places we have the following code snippet:

    val = @val.safeevaluate(@scope)
    if val.match(otherval)
        ...
    end

this way, we don’t have to modify this test specifically for handling regexes.

    # File lib/puppet/parser/ast/leaf.rb, line 190
    def evaluate(scope)
      self
    end

evaluate_match(value, scope, options = {}) click to toggle source

    # File lib/puppet/parser/ast/leaf.rb, line 194
    def evaluate_match(value, scope, options = {})
      value = value == :undef ? '' : value.to_s

      if matched = @value.match(value)
        scope.ephemeral_from(matched, options[:file], options[:line])
      end
      matched
    end

match(value) click to toggle source

    # File lib/puppet/parser/ast/leaf.rb, line 203
    def match(value)
      @value.match(value)
    end

to_s() click to toggle source

    # File lib/puppet/parser/ast/leaf.rb, line 207
    def to_s
      "/#{@value.source}/"
    end