4 module Puppet::Parser::Functions
5 newfunction(:hash, :type => :rvalue, :doc => <<-DOC
7 **Deprecated:** This function converts an array into a hash.
10 the converted array as a hash
11 @example Example Usage:
12 hash(['a',1,'b',2,'c',3]) # Returns: {'a'=>1,'b'=>2,'c'=>3}
14 > **Note:** This function has been replaced with the built-in ability to create a new value of almost any
15 data type - see the built-in [`Hash.new`](https://puppet.com/docs/puppet/latest/function.html#conversion-to-hash-and-struct) function
17 This example shows the equivalent expression in the Puppet language:
19 Hash(['a',1,'b',2,'c',3])
20 Hash([['a',1],['b',2],['c',3]])
25 raise(Puppet::ParseError, "hash(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
29 unless array.is_a?(Array)
30 raise(Puppet::ParseError, 'hash(): Requires array to work with')
36 # This is to make it compatible with older version of Ruby ...
40 raise(Puppet::ParseError, 'hash(): Unable to compute hash from array given')
47 # vim: set ts=2 sw=2 et :