ArticleDirectory
- Ruby-adding a directory to $ load_path-what does it do?
Similarities: all three are defined in the kernel and contain the meaning of something.
Differences:
1. requre and load are used for files ending with. RB.
2. Include is used to contain modules in a file (. Rb and other ending files.
3. requre is generally used to load library files, while load is used to load configuration files.
4. requre is loaded once, and load can be loaded multiple times.
How are you doing? Easy! Let's look at another example.
If ABC. RB contains a module Ma, and several classes such as Ca and CB. If you want to use resources in ABC. Rb in the ef. RB file, you have:
Require 'abc. rb'
If you want to use modules in ABC. Rb in a class of EF. RB, add
Include Ma
If you only want to use the ABC. RB module in a class of the ef. RB file, you have to do this:
Require 'abc. rb'
Include Ma
The two sentences tell you the difference.
Ruby-adding a directory to $ load_path-what does it do?
When you add/Users/you/scripts/Ruby
Directory to the load path, you can use:
Require 'example'
Instead:
Require '/users/you/scripts/Ruby/example. rb'
However, no solution is found for how to modify $ load_path. If you use require to load the file, you need to write the full path before loading the file. load is not required.