How does load differ from require in Ruby?

前端 未结 3 1065
无人及你
无人及你 2020-11-30 00:57

Is there any major difference between load and require in the Ruby on Rails applications? Or do they both have the same functionality?

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 01:31

    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.

提交回复
热议问题