summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorMatt Robinson <matt@puppetlabs.com>2011-04-08 11:55:33 -0700
committerMatt Robinson <matt@puppetlabs.com>2011-04-08 12:06:12 -0700
commit3094d423c498640f01d267ca7589533f862e9ac4 (patch)
tree5869f3237987b5d924a0517bd4bc2e6835e00b1d /lib/puppet
parente0a2e9180c20b664900586d7dedacd4172c24f6a (diff)
downloadpuppet-3094d423c498640f01d267ca7589533f862e9ac4.tar.gz
puppet-3094d423c498640f01d267ca7589533f862e9ac4.tar.xz
puppet-3094d423c498640f01d267ca7589533f862e9ac4.zip
maint: Add Array combinations method
Ruby < 1.8.7 doesn't have this method and we're using it in a test, so tests won't run on 1.8.6 until this is in place. It's probably a good thing to use much in implementation since it's written in pure Ruby when using < 1.8.7 and in C when in > 1.8.7, but then if you're using older Rubies you're probably not expecting much for performance anyway. Reviewed-by: Daniel Pittman <daniel@puppetlabs.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/util/monkey_patches.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/puppet/util/monkey_patches.rb b/lib/puppet/util/monkey_patches.rb
index a93c66b07..10a268409 100644
--- a/lib/puppet/util/monkey_patches.rb
+++ b/lib/puppet/util/monkey_patches.rb
@@ -90,3 +90,17 @@ if RUBY_VERSION == '1.8.1' || RUBY_VERSION == '1.8.2'
r
}
end
+
+class Array
+ # Ruby < 1.8.7 doesn't have this method but we use it in tests
+ def combination(num)
+ return [] if num < 0 || num > size
+ return [[]] if num == 0
+ return map{|e| [e] } if num == 1
+ tmp = self.dup
+ self[0, size - (num - 1)].inject([]) do |ret, e|
+ tmp.shift
+ ret += tmp.combination(num - 1).map{|a| a.unshift(e) }
+ end
+ end unless method_defined? :combination
+end