Skip to content

Instantly share code, notes, and snippets.

@bensonk
Created February 5, 2012 09:40
Show Gist options
  • Save bensonk/1744438 to your computer and use it in GitHub Desktop.
Save bensonk/1744438 to your computer and use it in GitHub Desktop.
#!/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