Class: Array

Inherits:
Object show all
Defined in:
lib/puppet/util/monkey_patches.rb

Instance Method Summary collapse

Instance Method Details

#combination(num) ⇒ Object

Ruby < 1.8.7 doesn’t have this method but we use it in tests



96
97
98
99
100
101
102
103
104
105
# File 'lib/puppet/util/monkey_patches.rb', line 96

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