Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / reject.rb
1 #
2 # reject.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:reject, :type => :rvalue, :doc => <<-DOC) do |args|
6     @summary
7       This function searches through an array and rejects all elements that match
8       the provided regular expression.
9
10     @return
11       an array containing all the elements which doesn'' match the provided regular expression
12
13     @example **Usage**
14
15       reject(['aaa','bbb','ccc','aaaddd'], 'aaa')
16
17       Would return: ['bbb','ccc']
18
19     > *Note:*
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/ }
22 DOC
23
24     if args.size != 2
25       raise Puppet::ParseError,
26             "reject(): Wrong number of arguments given #{args.size} for 2"
27     end
28
29     ary = args[0]
30     pattern = Regexp.new(args[1])
31
32     ary.reject { |e| e =~ pattern }
33   end
34 end
35
36 # vim: set ts=2 sw=2 et :