Skip to content

Instantly share code, notes, and snippets.

@peteb
Created July 31, 2014 16:36
Show Gist options
  • Save peteb/17bf6aff33387f2fa8f9 to your computer and use it in GitHub Desktop.
Save peteb/17bf6aff33387f2fa8f9 to your computer and use it in GitHub Desktop.
def esc(text)
text.upcase
end
def esc_sub(text, patterns)
patterns.each do |pattern, replacement|
if text =~ /^(.*)#{pattern}(.*)$/
return [esc_sub($1, patterns), replacement, esc_sub($2, patterns)].join
end
end
esc(text)
end
PATTERNS = [[/TILDE/, "mjau"], [/BORK/, 'xx']]
esc_sub("kattBORKvavuewreruhTILDEuasfasdfa", PATTERNS) # => "KATTxxVAVUEWRERUHmjauUASFASDFA"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment