require 'init' LoadError: no such file to load -- init - ruby

Haven't touched Ruby for ages so this really puzzled me.
Started up irb.
Then first line I ran was:
require 'init'
and I got this back:
LoadError: no such file to load -- init
Any idea what I'm doing wrong?

The error message says it quite clearly:
no such file to load -- init
So, either there is no such file (init.rb, init.so, init.jar, init.rba, etc. depending on the exact implementation of Ruby you use) or the file is not in a directory that is on the $LOAD_PATH.

Related

Do the .rb files in your db >>migrate have to be the same name as the rb files in your model folder?

I am fresh into Sinatra and Activerecord and I noticed I get a lot of errors such as
LoadError: cannot load such file -- ./model/character_houses
or
rake aborted!
NameError: uninitialized constant House
The first one is when I try to load into irb with require './app' for my main rb file.
The second is when I try to load a seed file.
Could someone just explain how file structures should be linked when using Sinatra and ActiveRecord. I have no problem setting the files up it's only when I try to check within irb or actually fill the tables.
A lot of the forums I see online pertain mostly to ruby on rails but we as a class are starting that after this so I am not sure if it is similar or relevant to my situation.
With sinatra the 'require' order is important
Dir.glob('./app/{exceptions,helpers}/*.rb').each do |file|
require file
end
require './app/controllers/api_controller'
require './app/uploaders/application_uploader'
Dir.glob('./app/{uploaders,jobs,controllers,models,etls,docs}/*.rb').each do |file|
require file
end
try 'require_relative app' with irb

Rspec a file which requires others. `require': cannot load such file

Is it possible to run an rspec on a file which requires other files?
my .rb file has the following lines:
require "colorize"
require "./board_initializer"
require "./pieces"
and when running a rake I get the following error:
.rvm/rubies/ruby-2.2.5/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- ./board_initializer (LoadError)
Thanks!
The error means board_initializer.rb isn't in the current working directory for __FILE__. Some ways to resolve this include:
Providing a valid filename argument to require.
Using require_relative with a valid relative path.
Modifying the current LOAD_PATH.
There are certainly other ways to resolve this, but they all amount to ensuring that board_initializer.rb can be found by the interpreter when you load or require the file.

Unable to load modules in ruby

I googled it, but no luck
I have a file called mdl.rb and main.rb, they both in the same folder
mdl.rb has module Test_module and method in it called say_hello, I want to use that method in my main.rb.
So my main.rb looks like this:
require 'mdl'
say_hello
but I get error:
in `require': cannot load such file -- mdl (LoadError)
You would use
require_relative 'mdl.rb'
See Ruby docs for require_relative.
(require_relative 'mdl' and require './mdl' also work, as pointed out in the comments by #MichaelBerkowski and #FĂ©lixSaparelli respectively.)

Can't get RSpec to work -- 'require': cannot load such file

I just spent three days of my life banging my head against the wall trying to figure out why a simple 'rake' would not pass my spec file.
If this happens to you: Do not have a space in any folder path!. Seriously. In fact do not have a space in anything you name from here on out.
Here is my console output:
(in /Users/*****/Desktop/Learning Ruby/learn_ruby)
$ rake
/Users/*******/Desktop/Learning Ruby/learn_ruby/00_hello/hello_spec.rb:116:
in `require': cannot load such file -- hello (LoadError)
The failure is caused by the line: require "hello"
This line tells Ruby that it needs to search the load path for a file named hello.rb. However, when it looks at the load path, it can't find that file. You should either remove that line and define your code directly in the spec file, or create a hello.rb file.
Newer versions of RSpec (2.11+ I believe) automatically add subdirectory lib to the load path. Based on your Rakefile it seems you are also loading the current lab directory and the subdirectory solution.
I'm guessing you're expected to put your solution in solution/hello.rb.
What worked for me was changing the require statement to a require_relative
I am using windows and an IDE

Why is autoload failing to load files for gems

I am trying to read emails in ruby using this gmail gem.
When I require 'gmail' in IRB or in a script, I get this error:
/Library/Ruby/Gems/1.8/gems/gmail-0.4.0/lib/gmail.rb:70:in connect_with_proper_client': no such file to load -- gmail/client (LoadError)
from /Library/Ruby/Gems/1.8/gems/gmail-0.4.0/lib/gmail.rb:48:in new
This is happening because autoload cannot file the 'gmail/client' file.
When I add require 'gmail/client' manually, the problem goes away till the next autoload call. This solution is unacceptable because I cannot anticipate which files to add in advance.
I found a similar question, however it didn't remedy my problem.

Resources