puppetlabs-stdlib/reverse.rb
Krzysztof Wilczynski 14b4ca8de2 Added support for strings to reverse.
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
2011-04-29 17:30:04 +01:00

27 lines
564 B
Ruby

#
# reverse.rb
#
module Puppet::Parser::Functions
newfunction(:reverse, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
raise(Puppet::ParseError, "reverse(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1
value = arguments[0]
klass = value.class
if not [Array, String].include?(klass)
raise(Puppet::ParseError, 'reverse(): Requires either an ' +
'array or string to work with')
end
result = value.reverse
return result
end
end
# vim: set ts=2 sw=2 et :