在 Ruby on Rails 应用程序中,load 和 require 之间有什么主要区别吗?或者它们都具有相同的功能?
Is there any major difference between load and require in the Ruby on Rails applications? Or do they both have the same functionality?
推荐答案require 在所有定义的搜索路径中搜索库并追加.rb 或 .so 到您输入的文件名.它还确保库仅包括一次.因此,如果您的应用程序需要库 A 和 B,而库 B 也需要库 A,则 A 将仅加载一次.
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.
使用 load 你需要添加库的全名,每次你都会加载它调用 load - 即使它已经在内存中.
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.
更多推荐
load 与 Ruby 中的 require 有何不同?
发布评论