class Puppet::Parser::AST::Regex

Public Class Methods

new(value: nil, file: nil, line: nil, pos: nil) click to toggle source
Calls superclass method Puppet::Parser::AST::Leaf::new
   # File lib/puppet/parser/ast/leaf.rb
53 def initialize(value: nil, file: nil, line: nil, pos: nil)
54   super(value: value, file: file, line: line, pos: pos)
55 
56   # transform value from hash options unless it is already a regular expression
57   @value = Regexp.new(@value) unless @value.is_a?(Regexp)
58 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
70 def evaluate(scope)
71   self
72 end
match(value) click to toggle source
   # File lib/puppet/parser/ast/leaf.rb
74 def match(value)
75   @value.match(value)
76 end
to_s() click to toggle source
   # File lib/puppet/parser/ast/leaf.rb
78 def to_s
79   Puppet::Pops::Types::PRegexpType.regexp_to_s_with_delimiters(@value)
80 end