Created
February 5, 2012 09:40
-
-
Save bensonk/1744438 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require "base64" | |
def b(string, context) | |
string.gsub /\^\{(.*?)\}/ do |s| | |
val = context.eval(s[2..-2]) | |
"b64d(\"#{Base64.encode64(val).strip}\")" | |
end | |
end | |
def test_one | |
foo = "awesome" | |
bar = "sauce" | |
puts b("one ^{foo} ^{bar}", binding) | |
end | |
def test_two | |
foo = "blargle" | |
bar = "fish" | |
puts b("two ^{foo} ^{bar}", binding) | |
end | |
def test_three | |
foo = "bar" | |
bar = "baz" | |
puts b("three ^{foo} ^{bar}", binding) | |
end | |
def test_four | |
foo = "ham" | |
bar = "egs" | |
puts b("four ^{foo} ^{bar}", binding) | |
end | |
test_one | |
test_two | |
test_three | |
test_four |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment