How to fix CLI load error : `require_relative': cannot load such file -Ruby
I've tried the solutions provided on Stackoverflow, related to this error. I have also tried a trial and error approach by rebuilding my gem and the error is still raised.
require_relative': cannot load such file -- /home/Jenhop8786/
In my bin folder my file looks like this:
#!/usr/bin/env ruby require_relative './lib/coding_schools' CodingSchools::CLI.new.call
In my lib folder my file looks like this:
require_relative "./coding_schools/version" require_relative "./coding_schools/cli"
-->Temporary -->coding_schools ->bin -coding-schools -console -setup ->lib -cli.rb -coding_schools.rb -version.rb -gitignore -coding_schools.gemspec -Gemfile -LICENSE -Rakefile -README.md
.refers to your current working directory where you started the Ruby process.
You can use
../to go up one directory if needed.
With your particular directory structure, files in
lib) can load files in
libusing code like this:
require_relative '../lib/cli' require_relative '../lib/coding_schools' require_relative '../lib/version'
libcan load eachother with code like this:
require_relative 'cli' require_relative 'coding_schools' require_relative 'version'
If you are really making a gem though, I'd recommend putting every file in
libinto a subdirectory with the same name as your gem. That is the convention. But after you do that, you have to fix some relative includes, so you should first get your code working and mark this as the accepted answer, then look into that.