Skip to content

Instantly share code, notes, and snippets.

@sfate
Created September 2, 2013 10:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfate/6411512 to your computer and use it in GitHub Desktop.
Save sfate/6411512 to your computer and use it in GitHub Desktop.
String interpolation in ruby style
String.prototype.format = function() {
var i = -1, args = arguments;
return this.replace(/#\{(.*?)\}/g, function(one, two) {
return (typeof args[0] == 'object')?args[0][two]:args[++i];
});
}
console.log("#{value}".format({value: "howdy, #{username}".format('sfate')}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment