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 given (#{arguments.size} for 2)") if arguments.size < 2
21 unless array.is_a?(Array)
22 raise(Puppet::ParseError, 'delete_at(): Requires array to work with')
27 if index.is_a?(String) and not index.match(/^\d+$/)
28 raise(Puppet::ParseError, 'delete_at(): You must provide non-negative numeric index')
33 # Numbers in Puppet are often string-encoded which is troublesome ...
36 if index > result.size - 1 # First element is at index 0 is it not?
37 raise(Puppet::ParseError, 'delete_at(): Given index exceeds size of array given')
40 result.delete_at(index) # We ignore the element that got deleted ...
46 # vim: set ts=2 sw=2 et :