Hello All
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.
My ruby version: ruby 1.8.6
Thanks in advance for your help!
···
--
Posted via http://www.ruby-forum.com/.
Kernel.load doesn't fill in gap of .rb or .so.
Its spec of ruby.
Thank you
···
---
Ayumu AIZAWA
twitter.com/ayumin
2009/12/7 Donghui Ouyang <exper.alpha@gmail.com>:
Hello All
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.
My ruby version: ruby 1.8.6
Thanks in advance for your help!
--
Posted via http://www.ruby-forum.com/\.
Evening Donghui,
Hello All
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.
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.
Hope things help clear things up
John
···
On Sun, Dec 6, 2009 at 9:09 PM, Donghui Ouyang <exper.alpha@gmail.com>wrote:
Thanks a lot, your answers are really helpful to me.
And John, I'm most grateful to you for your help.
···
--
Posted via http://www.ruby-forum.com/.