What is the difference between require_relative and require in Ruby?

后端 未结 7 1863
深忆病人
深忆病人 2020-11-22 10:15

What is the difference between require_relative and require in Ruby?

7条回答
  •  孤独总比滥情好
    2020-11-22 11:10

    Just look at the docs:

    require_relative complements the builtin method require by allowing you to load a file that is relative to the file containing the require_relative statement.

    For example, if you have unit test classes in the "test" directory, and data for them under the test "test/data" directory, then you might use a line like this in a test case:

    require_relative "data/customer_data_1"
    

提交回复
热议问题