Methods
Instance Public methods
Returns all possible combinations made from sample_size number of items from this list.
Parameters
- sample_size
- The length of each combination.
- sampler
- If given, each combination is passed to this block.
Returns all possible combinations of all possible lengths.
Parameters
- sampler
- If given, each combination is passed to this block.
Returns all possible enumerations made from sample_size number of items from this list.
Parameters
- sample_size
- The length of each enumeration.
- sampler
- If given, each enumeration is passed to this block.
# File lib/inochi/util/combo.rb, line 20 def enumeration(sample_size = self.length, &sampler) return [] if sample_size < 1 results = [] visitor = lambda do |parents| each do |child| result = parents + [child] if result.length < sample_size visitor.call result else yield result if block_given? results << result end end end visitor.call [] results end
Returns all possible enumerations of all possible lengths.
Parameters
- sampler
- If given, each enumeration is passed to this block.
Returns all possible permutations made from sample_size number of items from this list.
Parameters
- sample_size
- The length of each permutation.
- sampler
- If given, each permutation is passed to this block.