Skip to content

Instantly share code, notes, and snippets.

@dandorman
Created January 25, 2013 04:49
Show Gist options
  • Save dandorman/4631863 to your computer and use it in GitHub Desktop.
Save dandorman/4631863 to your computer and use it in GitHub Desktop.
require 'erb'
def interpolate(template, values = {})
template.gsub(/\{\{(.+?)\}\}/) { |token| values.fetch($1) { ERB.new("<%= #{token} %>").result(binding) } }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment