Last active
August 29, 2015 14:08
-
-
Save hookercookerman/4e21546bb1f0f669e8a5 to your computer and use it in GitHub Desktop.
Ruby Classes for Sinatra Endpoints
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
module SinatraCanHazClass | |
extend ActiveSupport::Concern | |
def initialize(app) | |
@app = app | |
end | |
def method_missing(method_name, *args, &block) | |
@app.respond_to?(method_name) ? @app.__send__(method_name, *args, &block) : super | |
end | |
module ClassMethods | |
def to_proc | |
this = self | |
Proc.new do | |
this.new(self).call | |
end | |
end | |
end | |
end | |
# Usage | |
get "/egg", &SomeClassWithMethodCall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment