Skip to content

Instantly share code, notes, and snippets.

@ogryzek
Created June 7, 2021 17:45
Show Gist options
  • Save ogryzek/9f16c5d81dc6fe0cd46fa95083c58c55 to your computer and use it in GitHub Desktop.
Save ogryzek/9f16c5d81dc6fe0cd46fa95083c58c55 to your computer and use it in GitHub Desktop.
require 'sinatra'
# require and use controllers from within the `./controller` directory
controller_paths = Dir["./controllers/*.rb"].each { |file| require_relative file }
controllers = controller_paths.map { |controller_path| controller_path[/controllers\/(.*?)_controller/m, 1] }
controllers.each { |controller| use Object.const_get("#{controller.capitalize}Controller") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment