Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Given a string containing placeholders (like [color]), enumerate all of the possible strings resulting from filling those placeholders with replacements (like red, blue).

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 string_enumerator.gemspec


You provide a list of replacements (“replace [color] with red and blue”) and then call the #enumerate method on a String:

?> u = => [ 'red', 'blue' ])
=> #<StringEnumerator...>
?> u.enumerate '[color]'
=> [ '', '' ]

The start and end of placeholders are marked with “[” and “]” (although you can override this if you want, see the tests.)

Multiple placeholders per string

You can define as many replacements as you want, which will exponentially increase the final number of enumerations

?> u2 = => [ 'red', 'blue' ], :taste => [ 'savory', 'sweet' ])
=> #<StringEnumerator...>
?> u2.enumerate '[color]/[taste]'
=> [ '', '', '', '' ]

Thanks to

Copyright 2011 Seamus Abshere

Something went wrong with that request. Please try again.