Forum: Ruby Re: GetoptLong Accessing the values with out looping

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.
F3b7b8756d0c7f71cc7460cc33aefaee?d=identicon&s=25 Berger, Daniel (Guest)
on 2006-05-16 16:20
(Received via mailing list)
> Makes perfect sense in this example you are still looping
> through the options. All though this is better on the eyes.
>
> I was hoping that the instance of getoptlong had some kind of
> method to get the value of one of the command line options.
>
> Paul

Yes, it sucks.  That's why I wrote the 'getopt' package.

gem install getopt :)

require 'getopt/long'
include Getopt

opts = Getopt::Long.new(['-d', '--date', REQUIRED])

if opts['d']
   # ...
end

Regards,

Dan




This communication is the property of Qwest and may contain confidential
or
privileged information. Unauthorized use of this communication is
strictly
prohibited and may be unlawful.  If you have received this communication
in error, please immediately notify the sender by reply e-mail and
destroy
all copies of the communication and any attachments.
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2006-05-16 16:48
(Received via mailing list)
On Tue, 16 May 2006, Berger, Daniel wrote:

>> Makes perfect sense in this example you are still looping
>
>
> Dan

nice dan.  i've been using optparse for all my stuff but it's usage is a
bit
obtuse.  perhaps i'll switch... does it support parsing arbitrary arrays
or
only ARGV?

regards.

-a
074597b4e64c139d5e1d51c52e475de2?d=identicon&s=25 Paul D. Kraus (Guest)
on 2006-05-16 18:05
(Received via mailing list)
>
>
> Yes, it sucks.  That's why I wrote the 'getopt' package.
>
> gem install getopt :)
>
> require 'getopt/long'
> include Getopt


I am having an issue with the script working. Is their some path
variable
that needs to be set for ruby to see the gem packages?

Initially i have the ubuntu ruby pkgs installed. I have removed them and
built ruby 1.8.4 and gems 0.8.11 built from source.

Any ideas?

*kraus@pkraus-laptop:~/sandbox/ruby/Daily Reports$ ./phones.rb
./phones.rb:3:in `require': no such file to load -- getopt/long
(LoadError)
        from ./phones.rb:3

kraus@pkraus-laptop:~/rubygems-0.8.11$ sudo gem install getopt
Attempting local installation of 'getopt'
Local gem file not found: getopt*.gem
Attempting remote installation of 'getopt'
Updating Gem source index for: http://gems.rubyforge.org
Successfully installed getopt-1.3.4
Installing RDoc documentation for getopt-1.3.4...


*
This topic is locked and can not be replied to.