summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-26 02:53:40 +0100
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-26 02:53:40 +0100
commit6bf04e1353b3a294aa7b7f5a0e70a5cc2743a3ee (patch)
treef99fa8a59473b53ba539915108fb53e8d56b05ff
parent528a16e3770b289c7bae315bf54d9ab07f8d6654 (diff)
downloadpuppet-stdlib-6bf04e1353b3a294aa7b7f5a0e70a5cc2743a3ee.tar.gz
puppet-stdlib-6bf04e1353b3a294aa7b7f5a0e70a5cc2743a3ee.tar.bz2
Small re-factor. We prefer our local clone of the array ...
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
-rw-r--r--shuffle.rb12
1 files changed, 6 insertions, 6 deletions
diff --git a/shuffle.rb b/shuffle.rb
index d92a3cd..37de723 100644
--- a/shuffle.rb
+++ b/shuffle.rb
@@ -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