]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Small re-factor. We prefer our local clone of the array ...
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Tue, 26 Apr 2011 01:53:40 +0000 (02:53 +0100)
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Tue, 26 Apr 2011 01:53:40 +0000 (02:53 +0100)
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
shuffle.rb

index d92a3cd3bd7f0cbafba5503871135e1574e4ae6b..37de723f9d2e45e874019bf7d689b6d4f33b6a10 100644 (file)
@@ -16,19 +16,19 @@ module Puppet::Parser::Functions
       raise(Puppet::ParseError, 'shuffle(): Requires an array to work with')
     end
 
-    return []    if array.size == 0
-    return array if array.size <= 1
+    result   = array.clone
+    elements = result.size
 
-    list     = array.clone
-    elements = list.size
+    return []     if result.size == 0
+    return result if result.size <= 1
 
     # Simple implementation of Fisher–Yates in-place shuffle ...
     elements.times do |i|
       j = rand(elements - i) + i
-      list[j], list[i] = list[i], list[j]
+      result[j], result[i] = result[i], result[j]
     end
 
-    return list
+    return result
   end
 end