I have two source files in the same directory: a.rb and b.rb
The content of a.rb is as follow:
puts “Hello form a.rb”
and b.rb is
load ‘a’
puts “Hello from b.rb”
load ‘a’
puts ‘Hello again from b.rb’
When I run the b.rb, It cause a LoadError: no such file to load
But if I replace ‘a’ with ‘a.rb’ in b.rb, the program run successfully.
It really confuse me.
load ‘a’
puts “Hello from b.rb”
load ‘a’
puts ‘Hello again from b.rb’
When I run the b.rb, It cause a LoadError: no such file to load
But if I replace ‘a’ with ‘a.rb’ in b.rb, the program run successfully.
It really confuse me.
I assume your confusion is why when you use require the .rb is not
needed
while for loaded it is. Require is for pulling in libraries and thus the
parameter to require is the library name which ruby then takes and
attempts
to find by adding .rb, or a library extension (.so on linux, .dll on
windows
and such). Load on the other hand is specifically for the loading of
files
and therefore a full filename is needed to be passed.
You’ll also find that while require will only load a library once - the
load
command will load a file as many times as it is called.