# Re: GetoptLong Accessing the values with out looping

**URL:** <https://www.ruby-forum.com/t/re-getoptlong-accessing-the-values-with-out-looping/60660>\
**Category:** Ruby\
**Created:** [May 16, 2006, 4:20pm UTC](https://www.ruby-forum.com/t/re-getoptlong-accessing-the-values-with-out-looping/60660 "2006-05-16T16:20:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [May 16, 2006, 4:20pm UTC](https://www.ruby-forum.com/t/re-getoptlong-accessing-the-values-with-out-looping/60660/1 "2006-05-16T16:20:27Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [May 16, 2006, 4:48pm UTC](https://www.ruby-forum.com/t/re-getoptlong-accessing-the-values-with-out-looping/60660/2 "2006-05-16T16:48:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [May 16, 2006, 6:05pm UTC](https://www.ruby-forum.com/t/re-getoptlong-accessing-the-values-with-out-looping/60660/3 "2006-05-16T18:05:43Z")

</div>

> 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](http://gems.rubyforge.org)  
Successfully installed getopt-1.3.4  
Installing RDoc documentation for getopt-1.3.4…

-
