5 module Puppet::Parser::Functions
6 newfunction(:delete_at, :type => :rvalue, :doc => <<-EOS
7 Deletes a determined indexed value from an array.
11 delete_at(['a','b','c'], 1)
13 Would return: ['a','c']
17 raise(Puppet::ParseError, "delete_at(): Wrong number of arguments " +
18 "given (#{arguments.size} for 2)") if arguments.size < 2
22 unless array.is_a?(Array)
23 raise(Puppet::ParseError, 'delete_at(): Requires array to work with')
28 if index.is_a?(String) and not index.match(/^\d+$/)
29 raise(Puppet::ParseError, 'delete_at(): You must provide ' +
30 'non-negative numeric index')
35 # Numbers in Puppet are often string-encoded which is troublesome ...
38 if index > result.size - 1 # First element is at index 0 is it not?
39 raise(Puppet::ParseError, 'delete_at(): Given index ' +
40 'exceeds size of array given')
43 result.delete_at(index) # We ignore the element that got deleted ...
49 # vim: set ts=2 sw=2 et :