Route Handlers Inside a Class

I have a Sinatra app setup where most of the logic is performed inside of various classes, and the post/get routes instantiate those classes and call their methods.

I'm thinking about whether putting the post/get route handlers inside of the classes themselves would be a better structure.

In any case, I'd like to know if it is possible. So for instance:

class Example
  def say_hello
    "Hello"
  end

  get '/hello' do
    @message = say_hello
  end
end

Without modification to the above, Sinatra will say there is no method say_hello on the SinatraApplication object.

12
задан Andrew Marshall 26 May 2014 в 16:38
поделиться