5 # TODO(Krzysztof Wilczynski): We need to add support for regular expression ...
7 module Puppet::Parser::Functions
8 newfunction(:delete, :type => :rvalue, :doc => <<-EOS
9 Deletes all instances of a given element from an array, substring from a
10 string, or key from a hash.
14 delete(['a','b','c','b'], 'b')
15 Would return: ['a','c']
17 delete({'a'=>1,'b'=>2,'c'=>3}, 'b')
18 Would return: {'a'=>1,'c'=>3}
20 delete({'a'=>1,'b'=>2,'c'=>3}, ['b','c'])
21 Would return: {'a'=>1}
23 delete('abracadabra', 'bra')
28 if (arguments.size != 2) then
29 raise(Puppet::ParseError, "delete(): Wrong number of arguments "+
30 "given #{arguments.size} for 2.")
33 collection = arguments[0].dup
34 Array(arguments[1]).each do |item|
37 collection.delete item
39 collection.gsub! item, ''
41 raise(TypeError, "delete(): First argument must be an Array, " +
42 "String, or Hash. Given an argument of class #{collection.class}.")
49 # vim: set ts=2 sw=2 et :