Reputation: 1
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 =>
How could this error be resolved?
Upvotes: 0
Views: 357
Reputation: 14865
NilClass
simply does not have a method called empty?
and args.extras
is obviously nil at the moment.
The best alternative in this case is blank?
which will return true if the array/string is empty or if args.extra
is nil.
task :stale => :environment do |_, args|
if args.extras.blank?
Here’s a nice table from here showing the differences between empty?
, blank?
, etc.
Upvotes: 3