Skip to content

Instantly share code, notes, and snippets.

@gbuesing
Created June 20, 2013 04:53
Show Gist options
  • Save gbuesing/5820386 to your computer and use it in GitHub Desktop.
Save gbuesing/5820386 to your computer and use it in GitHub Desktop.
Rack::AdHoc
# Allows you to write one-off middleware directly in config.ru. Good for prototyping.
#
# Example:
#
# use Rack::AdHoc do |app, env|
# status, headers, body = app.call(env)
# headers['X-Foo'] = 'bar'
# [status, headers, body]
# end
#
# run MyApp
#
class Rack::AdHoc
def initialize app, &block
@app = app
@block = block
end
def call env
@block.call @app, env
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment