Forum: Ruby on Rails I need some help with OptionsParser

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9fc9f31415f9384fbe7262fa916e16f5?d=identicon&s=25 Brian Corrigan (Guest)
on 2006-03-20 03:52
(Received via mailing list)
Hey all,

I must be doing something wrong here.  Im calling the following file
this way:
ruby script.rb -s 1234
or
ruby script.rb -s1111

#Code snip
require 'optparse'
opts = OptionParser.new
opts.on("-s", "--size VAL", Integer) do |val|
puts "-s #{val}"
puts val
end

But..no matter what I do, I don't get any values out.  I must be doing
something wrong??

Help!

THanks all,
Brian
119af50160cabfe1fb6f2f05f5018c64?d=identicon&s=25 James Ludlow (Guest)
on 2006-03-20 08:19
(Received via mailing list)
On 3/19/06, Brian Corrigan <brian.corrigan@mm-games.com> wrote:
>  puts "-s #{val}"
>  puts val
>  end
>
>  But..no matter what I do, I don't get any values out.  I must be doing
> something wrong??

After you set up your parser, you need to tell it to do something.

opts.parse(ARGV)

-- James
This topic is locked and can not be replied to.