Is there any major difference between load
and require
in the Ruby on Rails applications? Or do they both have the same functionality?
views:
72answers:
2
+2
A:
require
searches for the library in all the defined search paths and also appends
.rb or .so to the file name you enter. It also makes sure that a library is only
included once. So if your application requires library A and B and library B requries library A too A would be loaded only once.
With load
you need to add the full name of the library and it gets loaded every time you
call load
- even if it already is in memory.
Nikolaus Gradwohl
2010-07-03 07:12:55
Thank you sir , so we can say .rb is not require in loading . And "require" does not call all times , if its in memory?
Arpit Vaishnav
2010-07-03 07:17:38
yes require calls only once per session
Nikolaus Gradwohl
2010-07-03 08:45:58
A:
Another difference between Kernel#require
and Kernel#load
is that Kernel#load
takes an optional second argument that allows you to wrap the loaded code into an anonymous empty module.
Jörg W Mittag
2010-07-03 22:37:17