class Puppet::Pops::Evaluator::PuppetProc

Complies with Proc API by mapping a Puppet::Pops::Evaluator::Closure to a ruby Proc. Creating and passing an instance of this class instead of just a plain block makes it possible to inherit the parameter info and arity from the closure. Advanced users may also access the closure itself. The Puppet::Pops::Functions::Dispatcher uses this when it needs to get the Callable type of the closure.

The class is part of the Puppet Function API for Ruby and thus public API but a user should never create an instance of this class.

@api public

Attributes

closure[R]

@return [Puppet::Pops::Evaluator::Closure] the mapped closure @api public

Public Class Methods

new(closure, &block) click to toggle source

Creates a new instance from a closure and a block that will dispatch all parameters to the closure. The block must be similar to:

{ |*args| closure.call(*args) }

@param closure [Puppet::Pops::Evaluator::Closure] The closure to map @param &block [Block] The varargs block that invokes the closure.call method

@api private

Calls superclass method
   # File lib/puppet/pops/evaluator/puppet_proc.rb
21 def self.new(closure, &block)
22   proc = super(&block)
23   proc.instance_variable_set(:@closure, closure)
24   proc
25 end

Public Instance Methods

arity() click to toggle source

@return [Integer] the arity of the block @overrides Block.arity @api public

   # File lib/puppet/pops/evaluator/puppet_proc.rb
62 def arity
63   parameters.reduce(0) do |memo, param|
64     count = memo + 1
65     break -count unless param[0] == :req
66     count
67   end
68 end
lambda?() click to toggle source

@overrides Block.lambda? @return [Boolean] always false since this proc doesn't do the Ruby lambda magic @api public

   # File lib/puppet/pops/evaluator/puppet_proc.rb
34 def lambda?
35   false
36 end
parameters() click to toggle source

Maps the closure parameters to standard Block parameter info where each parameter is represented as a two element Array where the first element is :req, :opt, or :rest and the second element is the name of the parameter.

@return [Array<Array<Symbol>>] array of parameter info pairs @overrides Block.parameters @api public

   # File lib/puppet/pops/evaluator/puppet_proc.rb
46 def parameters
47   @closure.parameters.map do |param|
48     sym = param.name.to_sym
49     if param.captures_rest
50       [ :rest, sym ]
51     elsif param.value
52       [ :opt, sym ]
53     else
54       [ :req, sym ]
55     end
56   end
57 end