]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/lib/puppet/parser/functions/difference.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / difference.rb
1 #
2 # difference.rb
3 #
4
5 module Puppet::Parser::Functions
6   newfunction(:difference, :type => :rvalue, :doc => <<-EOS
7 This function returns the difference between two arrays.
8 The returned array is a copy of the original array, removing any items that
9 also appear in the second array.
10
11 *Examples:*
12
13     difference(["a","b","c"],["b","c","d"])
14
15 Would return: ["a"]
16     EOS
17   ) do |arguments|
18
19     # Two arguments are required
20     raise(Puppet::ParseError, "difference(): Wrong number of arguments " +
21       "given (#{arguments.size} for 2)") if arguments.size != 2
22
23     first = arguments[0]
24     second = arguments[1]
25
26     unless first.is_a?(Array) && second.is_a?(Array)
27       raise(Puppet::ParseError, 'difference(): Requires 2 arrays')
28     end
29
30     result = first - second
31
32     return result
33   end
34 end
35
36 # vim: set ts=2 sw=2 et :