Question

I am a ruby on rails developer and i confused a lot between Require and load used in environments at rails application . What exactly those two functions does .

Was it helpful?

Solution

I simply like to explain you about those two statements , those two are not functions in rails . Rails uses cache to cache the file when its loaded previously . when you get your cache true , then it uses require otherwise it uses load statement to load independent on cache .

I simply like to say that require is used to cache the file thats already loaded and load always hit the server to load files .

OTHER TIPS

Both load and require are quite similar in that they make sure that the specified class is loaded in your Ruby context.

Load

The main difference is that load will load the class every single time you call it, even if has already been loaded. There are some use cases for this, especially for unit testing.

Require

In contrast, the require just makes sure that the class is loaded. If it has already been loaded, it does nothing. If it has not been loaded yet, it loads it immediately.

Another minor difference is that when you load, you need to specify the file name .rb extension, whereas for require, you do NOT need the .rb extension.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top