lib/regexp-examples/helpers.rb in regexp-examples-0.0.0 vs lib/regexp-examples/helpers.rb in regexp-examples-0.0.1

- old
+ new

@@ -5,13 +5,15 @@ # element from each array # # For example: # permutations_of_strings [ ['a'], ['b'], ['c', 'd', 'e'] ] #=> ['acb', 'abd', 'abe'] # permutations_of_strings [ ['a', 'b'], ['c', 'd'] ] #=> [ 'ac', 'ad', 'bc', 'bd' ] - def self.permutations_of_strings(arrays_of_strings) - return arrays_of_strings[0] if arrays_of_strings.size == 1 + def self.permutations_of_strings(arrays_of_strings, options={}) first = arrays_of_strings.shift - first.product( permutations_of_strings(arrays_of_strings) ).map {|x| x.flatten.join} + return first if arrays_of_strings.empty? + first.product( permutations_of_strings(arrays_of_strings, options) ).map do |result| + options[:no_join] ? result.flatten : result.flatten.join + end end # TODO: For debugging only!! Delete this before v1.0 def self.show(regexp) s = regexp.examples