5 module Puppet::Parser::Functions
6 newfunction(:array_suffix, :type => :rvalue, :doc => <<-EOS
7 This function applies a suffix to all elements in an array.
11 array_suffix(['a','b','c'], 'p')
13 Will return: ['ap','bp','cp']
17 # Technically we support two arguments but only first is mandatory ...
18 raise(Puppet::ParseError, "array_suffix(): Wrong number of arguments " +
19 "given (#{arguments.size} for 1)") if arguments.size < 1
23 unless array.is_a?(Array)
24 raise Puppet::ParseError, "array_suffix(): expected first argument to be an Array, got #{array.inspect}"
27 suffix = arguments[1] if arguments[1]
30 unless suffix.is_a? String
31 raise Puppet::ParseError, "array_suffix(): expected second argument to be a String, got #{suffix.inspect}"
35 # Turn everything into string same as join would do ...
36 result = array.collect do |i|
38 suffix ? i + suffix : i
45 # vim: set ts=2 sw=2 et :