What does the nil mean in this gemfile entry?
这个gemfile条目中的nil是什么意思?
gem "hub", ">= 1.10.2", :require => nil
I found this question and answer for false;
我发现这个问题并回答错误;
Bundler: What does :require => false in a Gemfile mean?
Bundler:什么:Gemfile中的require => false是什么意思?
In this context, does nil behave the same as false?
在这种情况下,nil的行为与false相同吗?
3 个解决方案
#1
14
Yes, nil
and false
behave the same here: it makes Bundler not require the specified gem.
是的,nil和false在这里表现相同:它使Bundler不需要指定的gem。
#2
5
Require nil
or false
means that bundler will not load (require
) the specific gems. However, they will be in the $:
load paths, so you can require them explicitly any time you want to use them. It is a good practice to use this, for gems that are only needed in special cases (e.g. external scripts, rake tasks etc.).
要求零或错意味着捆绑器不会加载(需要)特定的宝石。但是,它们将位于$:加载路径中,因此您可以在需要使用它们时明确要求它们。对于仅在特殊情况下需要的宝石(例如外部脚本,rake任务等),使用它是一个好习惯。
#3
0
Whenever you specify a Gem in your Gemfile
and run bundle install
, bundler will go and install specified gem and load code for that Gem in you app by putting require 'whenever'
,this way bundler will load code for all of your Gems in your Rails app, and you can call any method from any Gem without any pain,like you do most of the time.
每当你在你的Gemfile中指定一个Gem并运行bundle install时,bundler就会在你的应用程序中安装指定的gem和加载代码,方法是将require'when',这样捆绑器将为你的Rails中的所有Gems加载代码应用程序,你可以从任何宝石调用任何方法没有任何痛苦,就像你大多数时间做的那样。
but Gems like whenever,faker or capistrano
are something which you do not need in your app code you need whenever code in your schedule.rb
file to manage crons and capistrano code in deploy.rb
file to customize deployment recipe so you need not to load code for these gems in your app code and wherever you want to call any method from these Gems you can manually require thsese gems by yourself by putting require "whenever"
. so you put :require => false
or :require => nil
in your Gemfile(both means the same) for these Gems, this way bundler will install that Gem but not load code for that Gem itself, you can do it whenever you want by simply putting like require 'whenever' in your case.
但Gems喜欢随时随地,你的应用程序代码中你不需要你需要的东西,你需要在schedule.rb文件中的代码,以管理deploy.rb文件中的crons和capistrano代码,以自定义部署配方,所以你不需要加载在您的应用程序代码中的这些宝石的代码以及您想要从这些宝石调用任何方法的任何地方,您可以通过将“需要时间”置于需要时手动要求这些宝石。所以你把Gemfile中的:require => false或:require => nil(两者都意味着相同)用于这些Gems,这样Bundler就会安装那个Gem但不加载Gem本身的代码,你可以随时随地做通过简单地在您的情况下像需要'随时'。
#1
14
Yes, nil
and false
behave the same here: it makes Bundler not require the specified gem.
是的,nil和false在这里表现相同:它使Bundler不需要指定的gem。
#2
5
Require nil
or false
means that bundler will not load (require
) the specific gems. However, they will be in the $:
load paths, so you can require them explicitly any time you want to use them. It is a good practice to use this, for gems that are only needed in special cases (e.g. external scripts, rake tasks etc.).
要求零或错意味着捆绑器不会加载(需要)特定的宝石。但是,它们将位于$:加载路径中,因此您可以在需要使用它们时明确要求它们。对于仅在特殊情况下需要的宝石(例如外部脚本,rake任务等),使用它是一个好习惯。
#3
0
Whenever you specify a Gem in your Gemfile
and run bundle install
, bundler will go and install specified gem and load code for that Gem in you app by putting require 'whenever'
,this way bundler will load code for all of your Gems in your Rails app, and you can call any method from any Gem without any pain,like you do most of the time.
每当你在你的Gemfile中指定一个Gem并运行bundle install时,bundler就会在你的应用程序中安装指定的gem和加载代码,方法是将require'when',这样捆绑器将为你的Rails中的所有Gems加载代码应用程序,你可以从任何宝石调用任何方法没有任何痛苦,就像你大多数时间做的那样。
but Gems like whenever,faker or capistrano
are something which you do not need in your app code you need whenever code in your schedule.rb
file to manage crons and capistrano code in deploy.rb
file to customize deployment recipe so you need not to load code for these gems in your app code and wherever you want to call any method from these Gems you can manually require thsese gems by yourself by putting require "whenever"
. so you put :require => false
or :require => nil
in your Gemfile(both means the same) for these Gems, this way bundler will install that Gem but not load code for that Gem itself, you can do it whenever you want by simply putting like require 'whenever' in your case.
但Gems喜欢随时随地,你的应用程序代码中你不需要你需要的东西,你需要在schedule.rb文件中的代码,以管理deploy.rb文件中的crons和capistrano代码,以自定义部署配方,所以你不需要加载在您的应用程序代码中的这些宝石的代码以及您想要从这些宝石调用任何方法的任何地方,您可以通过将“需要时间”置于需要时手动要求这些宝石。所以你把Gemfile中的:require => false或:require => nil(两者都意味着相同)用于这些Gems,这样Bundler就会安装那个Gem但不加载Gem本身的代码,你可以随时随地做通过简单地在您的情况下像需要'随时'。