Sha256: af100ea9c168d0680546d9fb75a5cb6829252bc10b0393834f5c4ca751c08bfe

Contents?: true

Size: 963 Bytes

Versions: 190

Compression:

Stored size: 963 Bytes

Contents

# Call a [lambda](https://docs.puppet.com/puppet/latest/reference/lang_lambdas.html)
# with the given arguments and return the result. Since a lambda's scope is
# [local](https://docs.puppetlabs.com/puppet/latest/reference/lang_lambdas.html#lambda-scope)
# to the lambda, you can use the `with` function to create private blocks of code within a
# class using variables whose values cannot be accessed outside of the lambda.
#
# @example Using `with`
#
# ~~~ puppet
# # Concatenate three strings into a single string formatted as a list.
# $fruit = with("apples", "oranges", "bananas") |$x, $y, $z| { 
#   "${x}, ${y}, and ${z}" 
# }
# $check_var = $x
# # $fruit contains "apples, oranges, and bananas"
# # $check_var is undefined, as the value of $x is local to the lambda.
# ~~~
#
# @since 4.0.0
#
Puppet::Functions.create_function(:with) do
  dispatch :with do
    repeated_param 'Any', :arg
    block_param
  end

  def with(*args)
    yield(*args)
  end
end

Version data entries

190 entries across 190 versions & 3 rubygems

Version Path
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/functions/with.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/functions/with.rb
puppet-5.3.7 lib/puppet/functions/with.rb
puppet-5.3.7-x86-mingw32 lib/puppet/functions/with.rb
puppet-5.3.7-x64-mingw32 lib/puppet/functions/with.rb
puppet-5.3.7-universal-darwin lib/puppet/functions/with.rb
puppet-4.10.12 lib/puppet/functions/with.rb
puppet-4.10.12-x86-mingw32 lib/puppet/functions/with.rb
puppet-4.10.12-x64-mingw32 lib/puppet/functions/with.rb
puppet-4.10.12-universal-darwin lib/puppet/functions/with.rb
puppet-4.10.11 lib/puppet/functions/with.rb
puppet-4.10.11-x86-mingw32 lib/puppet/functions/with.rb
puppet-4.10.11-x64-mingw32 lib/puppet/functions/with.rb
puppet-4.10.11-universal-darwin lib/puppet/functions/with.rb
puppet-5.3.6 lib/puppet/functions/with.rb
puppet-5.3.6-x86-mingw32 lib/puppet/functions/with.rb
puppet-5.3.6-x64-mingw32 lib/puppet/functions/with.rb
puppet-5.3.6-universal-darwin lib/puppet/functions/with.rb
bolt-0.17.1 vendored/puppet/lib/puppet/functions/with.rb
bolt-0.17.0 vendored/puppet/lib/puppet/functions/with.rb