lib/regexp-examples/helpers.rb in regexp-examples-1.0.2 vs lib/regexp-examples/helpers.rb in regexp-examples-1.1.0

- old
+ new

@@ -1,10 +1,8 @@ module RegexpExamples - # Given an array of arrays of strings, - # returns all possible perutations, - # for strings created by joining one - # element from each array + # Given an array of arrays of strings, returns all possible perutations + # for strings, created by joining one element from each array # # For example: # permutations_of_strings [ ['a'], ['b'], ['c', 'd', 'e'] ] #=> ['abc', 'abd', 'abe'] # permutations_of_strings [ ['a', 'b'], ['c', 'd'] ] #=> [ 'ac', 'ad', 'bc', 'bd' ] def self.permutations_of_strings(arrays_of_strings) @@ -27,11 +25,20 @@ end GroupResult.new(result.join, nil, subgroups) end def self.map_results(repeaters) + generic_map_result(repeaters, :result) + end + + def self.map_random_result(repeaters) + generic_map_result(repeaters, :random_result) + end + + private + def self.generic_map_result(repeaters, method) repeaters - .map {|repeater| repeater.result} + .map {|repeater| repeater.public_send(method)} .instance_eval do |partial_results| RegexpExamples.permutations_of_strings(partial_results) end end end