4 module Puppet::Parser::Functions
5 newfunction(:concat, :type => :rvalue, :doc => <<-DOC
7 Appends the contents of multiple arrays into array 1.
11 concat(['1','2','3'],'4') returns ['1','2','3','4']
12 concat(['1','2','3'],'4',['5','6','7']) returns ['1','2','3','4','5','6','7']
15 Since Puppet 4.0, you can use the `+`` operator for concatenation of arrays and
16 merge of hashes, and the `<<`` operator for appending:
18 `['1','2','3'] + ['4','5','6'] + ['7','8','9']` returns `['1','2','3','4','5','6','7','8','9']`
19 `[1, 2, 3] << 4` returns `[1, 2, 3, 4]`
20 `[1, 2, 3] << [4, 5]` returns `[1, 2, 3, [4, 5]]`
22 @return [Array] The single concatenated array
26 # Check that more than 2 arguments have been given ...
27 raise(Puppet::ParseError, "concat(): Wrong number of arguments given (#{arguments.size} for < 2)") if arguments.size < 2
31 # Check that the first parameter is an array
33 raise(Puppet::ParseError, 'concat(): Requires array to work with')
40 result += (x.is_a?(Array) ? x : [x])
47 # vim: set ts=2 sw=2 et :