Skip to content

Instantly share code, notes, and snippets.

@rf-
Created January 12, 2013 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rf-/4516615 to your computer and use it in GitHub Desktop.
Save rf-/4516615 to your computer and use it in GitHub Desktop.
def insert_before(klass, options={})
instance = new(nil, options)
call_without = "call_without_#{instance.object_id}"
call_with = "call_with_#{instance.object_id}"
klass.class_eval do
define_method call_with do |env|
instance.app = proc { |env| send call_without, env }
instance.call(env)
end
alias_method_chain :call, instance.object_id.to_s
end
end
def insert_before(klass, options={})
instance = new(nil, options)
klass.class_eval do
unbound_call = instance_method(:call)
define_method(:call) do |env|
instance.app = unbound_call.bind(self)
instance.call(env)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment