Created
January 12, 2013 07:42
-
-
Save rf-/4516615 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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