lib/puppet/parser/ast/lambda.rb
# Calls the lambda.
# Assigns argument values in a nested local scope that should be used to evaluate the lambda
# and then evaluates the lambda.
# @param scope [Puppet::Scope] the calling scope
# @return [Object] the result of evaluating the expression(s) in the lambda
#
Calls the lambda.
Assigns argument values in a nested local scope that should be used to evaluate the lambda
and then evaluates the lambda.
Calls the lambda . Assigns argument values in a nested local scope that should be used to evaluate the lambda and then evaluates the lambda .
def call(scope, *args)
      raise Puppet::ParseError, "Too many arguments: #{args.size} for #{parameters.size}" unless args.size <= parameters.size
      merged = parameters.zip(args)
      missing = merged.select { |e| !e[1] && e[0].size == 1 }
      unless missing.empty?
        optional = parameters.count { |p| p.size == 2 }
        raise Puppet::ParseError, "Too few arguments; #{args.size} for #{optional > 0 ? ' min ' : ''}#{parameters.size - optional}"
      end
      evaluated = merged.collect do |m|
        n = m[0].is_a?(Array) ? m[0][0] : m[0]
        v = m[1] || (m[0][1]).safeevaluate(scope) 
        [n, v]
      end
      begin
        elevel = scope.ephemeral_level
        scope.ephemeral_from(Hash[evaluated], file, line)
        result = safeevaluate(scope)
      ensure
        scope.unset_ephemeral_var(elevel)
        result ||= nil
      end
      result
    end
def call ( scope , * args ) raise Puppet :: ParseError , "Too many arguments: #{args.size} for #{parameters.size}" unless args . size <= parameters . size merged = parameters . zip ( args ) missing = merged . select { | e | ! e [ 1 ] && e [ 0 ] . size == 1 } unless missing . empty? optional = parameters . count { | p | p . size == 2 } raise Puppet :: ParseError , "Too few arguments; #{args.size} for #{optional > 0 ? ' min ' : ''}#{parameters.size - optional}" end evaluated = merged . collect do | m | n = m [ 0 ] . is_a? ( Array ) ? m [ 0 ] [ 0 ] : m [ 0 ] v = m [ 1 ] || ( m [ 0 ] [ 1 ] ) . safeevaluate ( scope ) [ n , v ] end begin elevel = scope . ephemeral_level scope . ephemeral_from ( Hash [ evaluated ] , file , line ) result = safeevaluate ( scope ) ensure scope . unset_ephemeral_var ( elevel ) result ||= nil end result end
Calls the lambda.
Calls the lambda .
# Ruby 1.8.7 zip seems to produce a different result than Ruby 1.9.3 in some situations # given value or default expression value # Store the evaluated name => value associations in a new inner/local/ephemeral scope # (This is made complicated due to the fact that the implementation of scope is overloaded with # functionality and an inner ephemeral scope must be used (as opposed to just pushing a local scope # on a scope "stack").
the result of evaluating the expression(s) in the lambda
the result of evaluating the expression ( s ) in the lambda
Object
scope
the calling scope
the calling scope
args
<not_specific>