Skip to content

Instantly share code, notes, and snippets.

@hookercookerman
Last active August 29, 2015 14:08
Show Gist options
  • Save hookercookerman/4e21546bb1f0f669e8a5 to your computer and use it in GitHub Desktop.
Save hookercookerman/4e21546bb1f0f669e8a5 to your computer and use it in GitHub Desktop.
Ruby Classes for Sinatra Endpoints
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