4 module Puppet::Parser::Functions
5 newfunction(:reject, :type => :rvalue, :doc => <<-DOC) do |args|
7 This function searches through an array and rejects all elements that match
8 the provided regular expression.
11 an array containing all the elements which doesn'' match the provided regular expression
15 reject(['aaa','bbb','ccc','aaaddd'], 'aaa')
17 Would return: ['bbb','ccc']
20 Since Puppet 4.0.0 the same is in general done with the filter function. Here is the equivalence of the reject() function:
21 ['aaa','bbb','ccc','aaaddd'].filter |$x| { $x !~ /aaa/ }
25 raise Puppet::ParseError,
26 "reject(): Wrong number of arguments given #{args.size} for 2"
30 pattern = Regexp.new(args[1])
32 ary.reject { |e| e =~ pattern }
36 # vim: set ts=2 sw=2 et :