Class: Array
- Defined in:
- lib/vendor/puppet/util/zaml.rb,
lib/vendor/puppet/util/monkey_patches.rb
Instance Method Summary collapse
-
#combination(num) ⇒ Object
Ruby < 1.8.7 doesn’t have this method but we use it in tests.
- #to_zaml(z) ⇒ Object
Instance Method Details
#combination(num) ⇒ Object
Ruby < 1.8.7 doesn’t have this method but we use it in tests
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/vendor/puppet/util/monkey_patches.rb', line 104 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 |
#to_zaml(z) ⇒ Object
362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/vendor/puppet/util/zaml.rb', line 362 def to_zaml(z) z.first_time_only(self) { z.nested { if empty? z.emit('[]') else each { |v| z.nl('- '); v.to_zaml(z) } end } } end |