load 与 Ruby 中的 require 有何不同? [英] How does load differ from require in Ruby?

查看:32
本文介绍了load 与 Ruby 中的 require 有何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Ruby on Rails 应用程序中,loadrequire 之间有什么主要区别吗?或者它们都具有相同的功能?

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 有何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆