Created
May 11, 2013 10:58
-
-
Save heftig/5559638 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def caseperm(str, num) | |
str.each_char.map.with_index do |c,i| | |
if num[i] == 0 | |
c.downcase | |
else | |
c.upcase | |
end | |
end.join | |
end | |
def caseperms(str) | |
if block_given? | |
(2**str.length).times do |i| | |
yield caseperm(str, i) | |
end | |
else | |
enum_for(__method__, str) | |
end | |
end | |
caseperms("foo").to_a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment