[英]rake aborted! undefined method `empty?' for nil:NilClass
I have some rake tasks defined and within those tasks; 我在其中定义了一些耙任务。 there is a code as follows 有一个代码如下
task :stale => :environment do |_, args|
if args.extras.empty?
When I run the task; 当我运行任务时; it gets aborted with the following error 它因以下错误而中止
rake aborted! 耙子流产了! undefined method `empty?' 未定义的方法“空”? for nil:NilClass /lib/tasks/:387:in `block (3 levels) in ' /vendor/bundle/ruby/2.2.0/gems/bugsnag-2.8.12/lib/bugsnag/rake.rb:12:in `execute_with_bugsnag' Tasks: TOP => 对于nil:NilClass / lib / tasks /:387:在'/vendor/bundle/ruby/2.2.0/gems/bugsnag-2.8.12/lib/bugsnag/rake.rb:12中的块(3个级别)中:在`execute_with_bugsnag'任务中:TOP =>
How could this error be resolved? 如何解决此错误?
NilClass
simply does not have a method called empty?
NilClass
根本没有称为empty?
的方法empty?
and args.extras
is obviously nil at the moment. 而args.extras
目前显然为零。
The best alternative in this case is blank?
在这种情况下最好的选择是blank?
which will return true if the array/string is empty or if args.extra
is nil. 如果数组/字符串为空或args.extra
为nil,则返回true。
task :stale => :environment do |_, args|
if args.extras.blank?
Here's a nice table from here showing the differences between empty?
下面是一个不错的表在这里显示之间的差异empty?
, blank?
, blank?
, etc. 等
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.