Suggest different variables to use if we want to tunnel both v4 and v6
[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     This function searches through an array and rejects all elements that match
7     the provided regular expression.
8
9     *Examples:*
10
11         reject(['aaa','bbb','ccc','aaaddd'], 'aaa')
12
13     Would return:
14
15         ['bbb','ccc']
16
17     Note that since Puppet 4.0.0 the same is in general done with the filter function. Here is the
18     equivalence of the reject() function:
19
20         ['aaa','bbb','ccc','aaaddd'].filter |$x| { $x !~ /aaa/ }
21 DOC
22
23     if args.size != 2
24       raise Puppet::ParseError,
25             "reject(): Wrong number of arguments given #{args.size} for 2"
26     end
27
28     ary = args[0]
29     pattern = Regexp.new(args[1])
30
31     ary.reject { |e| e =~ pattern }
32   end
33 end
34
35 # vim: set ts=2 sw=2 et :