Object.extend = function(dest, src) {
  for (var i in src)
    dest[i] = src[i];
};

Object.extend(String.prototype, {
  format: function(hash) {
    var args = arguments;
    return this.replace(/(^|.|\r|\n)(#\{(?:((?:#|\$)\d+)|(.*?))\})/g, function(match, before, template, num, name) {
      return before == '\\' ? template : before + (num ? args[num.substring(1)] : hash[name] == undefined ? '' : hash[name]);
    });
  }
})
