Skip to content

Instantly share code, notes, and snippets.

# We want a uniform way of reducing a code tree
# so the easiest way to do that is to extend
# Object with a call method and whenever any
# object does not define it's own call method we
# assume the object is implicitly claiming it wants
# to return itself. Since Object is almost at the top
# of the hierarchy almost anything we are interested
# in will work as expected.
class Object
def call
require 'rack'
class Object
def webapp
tap {
def self.call(env)
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, send(func, *attrs)]
end
}