Greetings,
I am working on a project and I added command line options. Today, I
took the fateful step in adding the capability to do multiple options in
the program. For some reason, the code, which worked perfectly before
this, now spews out the error:
undefined method “-” for nil:NilClass (NoMethodError)
The code in question is:
dateArr[0] = DateTime.parse(ARGV[1])
Now, this error pops up because ARGV[1] is nil. But if I run the
program :
ruby Hercules.rb -c 2010-04-15
ARGV[1] should be 2010-04-15. What is the problem here?
That is more of the code in question. Hope if helps.
No, but it will help if you can provide a complete, standalone program
which demonstrates the problem. Either write a program from scratch just
to demonstrate the problem, or keep trimming out code from your existing
program until you can no longer demonstrate it.
Figured it out. Turns out, I was checking if ARGV’s size was 0, then
trying it. Clearly, if ARGV was 0, there are no options or arguments.
Thus, dateArr[0] is nil and cannot be used for equations. Thanks for
all your help!
Cheers,
dlucci
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.