Puppet Function: reverse

Defined in:
vendor_modules/stdlib/lib/puppet/parser/functions/reverse.rb
Function type:
Ruby 3.x API

Summary

Reverses the order of a string or array.

Overview

reverse()Any

> Note: that the same can be done with the reverse_each() function in Puppet.

Returns:

  • (Any)

    reversed string or array



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'vendor_modules/stdlib/lib/puppet/parser/functions/reverse.rb', line 7

newfunction(:reverse, type: :rvalue, doc: <<-DOC
  @summary
    Reverses the order of a string or array.

  @return
    reversed string or array

  > *Note:* that the same can be done with the reverse_each() function in Puppet.
  DOC
) do |arguments|
  raise(Puppet::ParseError, "reverse(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?

  value = arguments[0]

  unless value.is_a?(Array) || value.is_a?(String)
    raise(Puppet::ParseError, 'reverse(): Requires either array or string to work with')
  end

  result = value.reverse

  return result
end