Difference between Ruby's require, load, and include

Source: Internet
Author: User
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/RubyDirectory 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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.