]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/lib/puppet/parser/functions/any2array.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / any2array.rb
1 #
2 # any2array.rb
3 #
4
5 module Puppet::Parser::Functions
6   newfunction(:any2array, :type => :rvalue, :doc => <<-EOS
7 This converts any object to an array containing that object. Empty argument
8 lists are converted to an empty array. Arrays are left untouched. Hashes are
9 converted to arrays of alternating keys and values.
10     EOS
11   ) do |arguments|
12
13     if arguments.empty?
14         return []
15     end
16
17     if arguments.length == 1
18         if arguments[0].kind_of?(Array)
19             return arguments[0]
20         elsif arguments[0].kind_of?(Hash)
21             result = []
22             arguments[0].each do |key, value|
23                 result << key << value
24             end
25             return result
26         end
27     end
28
29     return arguments
30   end
31 end
32
33 # vim: set ts=2 sw=2 et :