Update stdlib and concat to 6.1.0 both
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / reverse.rb
1 #
2 # reverse.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:reverse, :type => :rvalue, :doc => <<-DOC
6     @summary
7       Reverses the order of a string or array.
8
9     @return
10       reversed string or array
11
12     > *Note:* that the same can be done with the reverse_each() function in Puppet.
13     DOC
14              ) do |arguments|
15
16     raise(Puppet::ParseError, "reverse(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
17
18     value = arguments[0]
19
20     unless value.is_a?(Array) || value.is_a?(String)
21       raise(Puppet::ParseError, 'reverse(): Requires either array or string to work with')
22     end
23
24     result = value.reverse
25
26     return result
27   end
28 end
29
30 # vim: set ts=2 sw=2 et :