I want to require a file called config.rb in a different ruby file called basics.rb. I’m using Sinatra as my web framework. I’m sure there’s a way to do this, I just can’t find anything in the docs.
Hopefully it would look something like
post '/' do
require 'config.rb'
// logic
end
If config.rb is in your load path, you can require it at the top of your basics.rb file with
require 'config'. If it is not in your load path, you’ll need something likerequire '/path/to/your/config'.The code you’ve posted will require the file. But only when someone POSTs to ‘/’.
Also, it’s normal to omit the .rb extension when requiring ruby files. But you can include it if you like.
You can view your load path by inspecting the global variable
$LOAD_PATH. From the command lineruby -e 'puts $LOAD_PATH'will print it for your version of ruby. You can also add directories to your load path.