Вы можете сделать метод, который создает маршруты.
Смотрите пример, который я сделал:
require 'sinatra'
class UserController
def index
'UserController -> index!'
end
def posts
'UserController -> posts!'
end
end
def route_get(url, call)
controller_class, method = call.split('#')
controller_class = Object.const_get(controller_class)
Sinatra::Base.get url do
controller_class.new.send(method)
end
end
route_get '/', 'UserController#index'
route_get '/users', 'UserController#index'
route_get '/users/posts', 'UserController#posts'
Если хотите, вы можете сделать для других методов HTTP. Или вы можете передать другие аргументы.