]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Added support for strings to reverse.
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Fri, 29 Apr 2011 16:30:04 +0000 (17:30 +0100)
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Fri, 29 Apr 2011 16:30:04 +0000 (17:30 +0100)
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
reverse.rb

index 6aa11f4c692c7857876ca7866238f12dfa6e2ad4..86dee28c9e61d1f8d49a12fd065b1911bf468aff 100644 (file)
@@ -2,8 +2,6 @@
 # reverse.rb
 #
 
-# TODO(Krzysztof Wilczynski): Support for strings would be nice too ...
-
 module Puppet::Parser::Functions
   newfunction(:reverse, :type => :rvalue, :doc => <<-EOS
     EOS
@@ -12,13 +10,15 @@ module Puppet::Parser::Functions
     raise(Puppet::ParseError, "reverse(): Wrong number of arguments " +
       "given (#{arguments.size} for 1)") if arguments.size < 1
 
-    array = arguments[0]
+    value = arguments[0]
+    klass = value.class
 
-    if not array.is_a?(Array)
-      raise(Puppet::ParseError, 'reverse(): Requires an array to work with')
+    if not [Array, String].include?(klass)
+      raise(Puppet::ParseError, 'reverse(): Requires either an ' +
+        'array or string to work with')
     end
 
-    result = array.reverse
+    result = value.reverse
 
     return result
   end