# File lib/puppet/parser/ast/leaf.rb, line 176 def initialize(hash) super @value = Regexp.new(@value) unless @value.is_a?(Regexp) end
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
# 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
# File lib/puppet/parser/ast/leaf.rb, line 203 def match(value) @value.match(value) end
# File lib/puppet/parser/ast/leaf.rb, line 207 def to_s "/#{@value.source}/" end