5 module Puppet::Parser::Functions
6 newfunction(:delete, :type => :rvalue, :doc => <<-EOS
7 Deletes all instances of a given element from an array, substring from a
8 string, or key from a hash.
12 delete(['a','b','c','b'], 'b')
13 Would return: ['a','c']
15 delete({'a'=>1,'b'=>2,'c'=>3}, 'b')
16 Would return: {'a'=>1,'c'=>3}
18 delete({'a'=>1,'b'=>2,'c'=>3}, ['b','c'])
19 Would return: {'a'=>1}
21 delete('abracadabra', 'bra')
26 raise(Puppet::ParseError, "delete(): Wrong number of arguments given #{arguments.size} for 2") unless arguments.size == 2
28 collection = arguments[0].dup
29 Array(arguments[1]).each do |item|
32 collection.delete item
34 collection.gsub! item, ''
36 raise(TypeError, "delete(): First argument must be an Array, String, or Hash. Given an argument of class #{collection.class}.")
43 # vim: set ts=2 sw=2 et :