4 module Puppet::Parser::Functions
5 newfunction(:delete_values, :type => :rvalue, :doc => <<-DOC
6 Deletes all instances of a given value from a hash.
10 delete_values({'a'=>'A','b'=>'B','c'=>'C','B'=>'D'}, 'B')
12 Would return: {'a'=>'A','c'=>'C','B'=>'D'}
14 Note that since Puppet 4.0.0 the equivalent can be performed with the filter() function in Puppet:
16 $array.filter |$val| { $val != 'B' }
17 $hash.filter |$key, $val| { $val != 'B' }
22 raise(Puppet::ParseError, "delete_values(): Wrong number of arguments given (#{arguments.size} of 2)") if arguments.size != 2
24 hash, item = arguments
26 unless hash.is_a?(Hash)
27 raise(TypeError, "delete_values(): First argument must be a Hash. Given an argument of class #{hash.class}.")
29 hash.dup.delete_if { |_key, val| item == val }