4 module Puppet::Parser::Functions
5 newfunction(:hash, :type => :rvalue, :doc => <<-DOC
6 This function converts an array into a hash.
10 hash(['a',1,'b',2,'c',3])
12 Would return: {'a'=>1,'b'=>2,'c'=>3}
14 Note: Since Puppet 5.0.0 type conversions can in general be performed by using the Puppet Type System.
15 See the function new() in Puppet for a wide range of available type conversions.
16 This example shows the equivalent expression in the Puppet language:
18 Hash(['a',1,'b',2,'c',3])
19 Hash([['a',1],['b',2],['c',3]])
23 raise(Puppet::ParseError, "hash(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
27 unless array.is_a?(Array)
28 raise(Puppet::ParseError, 'hash(): Requires array to work with')
34 # This is to make it compatible with older version of Ruby ...
38 raise(Puppet::ParseError, 'hash(): Unable to compute hash from array given')
45 # vim: set ts=2 sw=2 et :