permutations 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/permutations.rb +2 -2
- data/permutations.gemspec +1 -1
- metadata +1 -1
data/lib/permutations.rb
CHANGED
@@ -17,10 +17,10 @@ module Permutations
|
|
17
17
|
module String
|
18
18
|
# Create multi-level string permutations
|
19
19
|
# "{a,b,c}{1,2,3}".permutations # => ["a1", "a2", "a3", "b1", "b2", "b3", "c1", "c2", "c3"]
|
20
|
-
def permutations
|
20
|
+
def permutations(separator=',')
|
21
21
|
matches = self.scan(/(\{(.*?)\})/)
|
22
22
|
substitutions = matches.map{|match| match[0]}
|
23
|
-
permutations = matches.map{|match| match[1].split(/\s
|
23
|
+
permutations = matches.map{|match| match[1].split(/\s*#{Regexp.escape(separator)}\s*/)}.permutations
|
24
24
|
permutations.map do |permutation|
|
25
25
|
permutated_string = self.dup
|
26
26
|
permutation.each_with_index do |choice, index|
|
data/permutations.gemspec
CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.name = 'permutations'
|
4
4
|
s.summary = "Permutations is a library that allows you to generate permutations from Arrays and Strings."
|
5
5
|
s.description = s.summary
|
6
|
-
s.version = '0.1.
|
6
|
+
s.version = '0.1.1'
|
7
7
|
s.date = '2010-01-21'
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Wes Oldenbeuving"]
|