Skip to content

Instantly share code, notes, and snippets.

@tamtam180
Created June 18, 2012 19:29
Show Gist options
  • Save tamtam180/2950233 to your computer and use it in GitHub Desktop.
Save tamtam180/2950233 to your computer and use it in GitHub Desktop.
JavaScriptで簡単なRubyの変数展開をサポートする
function format(template, param) {
param = param || [];
return template.replace(/#{(\w+?)}/g, function(matcher, key) {
var data = param[key] || '';
return (typeof data === "function") ? data() : data;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment