Skip to content

Instantly share code, notes, and snippets.

@porras
Created October 2, 2014 13:35
Show Gist options
  • Save porras/e9b7edfea6b817ac8afe to your computer and use it in GitHub Desktop.
Save porras/e9b7edfea6b817ac8afe to your computer and use it in GitHub Desktop.
Run your objects as web apps in an insanely decoupled way
class Object
def to_app
lambda do |env|
_, method, args = env['REQUEST_PATH'].split('/')
[200, {}, [self.send(method, *args).to_s]]
end
end
end
class HelloWorld
def hello(name)
"Hello, #{name}!"
end
end
run HelloWorld.new.to_app
# This is not my idea, I read it time ago and wasn't able to find it today so I rewrote it (not sure the implementation is the same)
# start running rackup
# $ curl http://localhost:9292/hello/Txus
# Hello, Txus!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment