Skip to content

Instantly share code, notes, and snippets.

@botanicus
botanicus / mixin.js
Created May 25, 2010 09:13 — forked from rkh/mixin.js
JS: Object.prototype.extend()
var sys = require("sys");
var extend = function extend (another) {
var prototype = this.__proto__;
this.__proto__ = another;
another.__proto__ = prototype;
return this;
};
Object.defineProperty(Object.prototype, "extend", {value: extend });
require 'rango/mixins/rendering'
class Application < Merb::Controller
include Rango::ExplicitRendering
def scope
@scope ||= begin
super.tap do |scope|
scope.extend(ResourceHelper)
scope.instance_variable_set("@params", self.request.params)
end
Surround a heredoc with quotes and you can continue the code on the same line:
render :status => 404, :text => <<-'EOH' and return unless setup
article not found<br/>
I, as a server, have failed<br/>
https?
EOH
Quotes also give you more freedom/creativity with the terminal ID:
require "rubygems"
require "rbench"
def omg_slow
return 1
end
def omg_fast
1
end
# ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-darwin9.6.0]
user system total real
by_define_method 0.680000 0.000000 0.680000 ( 0.700586)
by_explicit_definition 0.560000 0.010000 0.570000 ( 0.581977)
by_eval 0.550000 0.000000 0.550000 ( 0.553484)
by_class_eval 0.540000 0.010000 0.550000 ( 0.561800)
by_class_eval_block 0.540000 0.000000 0.540000 ( 0.548041)
by_module_eval 0.550000 0.010000 0.560000 ( 0.560635)
by_module_eval_block 0.520000 0.000000 0.520000 ( 0.539168)