Skip to content

Instantly share code, notes, and snippets.

@heftig
Created May 11, 2013 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heftig/5559638 to your computer and use it in GitHub Desktop.
Save heftig/5559638 to your computer and use it in GitHub Desktop.
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