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.
Brian C. (Guest)
on 2006-03-20 04: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
James L. (Guest)
on 2006-03-20 09:19
(Received via mailing list)
On 3/19/06, Brian C. <removed_email_address@domain.invalid> 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.