From: Mat Brown on 12 May 2010 17:24 Hi Derril, When working with command-line options, you'll have a much better time working with OptionParser -- it's part of the Ruby standard library: http://ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html Mat On Wed, May 12, 2010 at 17:16, Derril Lucci <derril.lucci(a)gmail.com> wrote: > 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? > > Thank you, > Â dlucci > -- > Posted via http://www.ruby-forum.com/. > >
From: Jesús Gabriel y Galán on 12 May 2010 17:24 On Wed, May 12, 2010 at 11:16 PM, Derril Lucci <derril.lucci(a)gmail.com> wrote: > 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? It must be something else, cause this works for me: require 'date' puts DateTime.parse(ARGV[1]) and calling this as ruby test.rb -c 2010-04-15 prints the date. Can you show the full code that errors? Jesus.
From: Derril Lucci on 12 May 2010 17:32 Certainly. opts is an array of Getoptlong type and holds the options and their requirements. opts.each do |opt, arg| case opt when "--date", "-d" dateArr[0] = DateTime.parse(ARGV[1])
|
Pages: 1 Prev: Determine if IE has an open modal window win32ole Next: [ANN] JRuby 1.5.0 Released |