# Re: GetoptLong Accessing the values with out looping

**URL:** <https://www.ruby-forum.com/t/re-getoptlong-accessing-the-values-with-out-looping/94850>\
**Category:** Ruby\
**Created:** [May 16, 2006, 4:52pm UTC](https://www.ruby-forum.com/t/re-getoptlong-accessing-the-values-with-out-looping/94850 "2006-05-16T16:52:09Z")\
**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:52pm UTC](https://www.ruby-forum.com/t/re-getoptlong-accessing-the-values-with-out-looping/94850/1 "2006-05-16T16:52:09Z")

</div>

> > > From: Paul D. Kraus [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]  
> > > options. All though this is better on the eyes.
> > 
> > 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

Just ARGV, I’m afraid. I suppose you could push args onto ARGV directly  
as a workaround.

May I ask when you would want to parse an arbitrary array? I’m curious.

Oh, and when I said, “Yes, it sucks”, I was referring to getoptlong in  
the stdlib, not your code in particular. Just thought I should clarify  
that. 🙂

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, 5:23pm UTC](https://www.ruby-forum.com/t/re-getoptlong-accessing-the-values-with-out-looping/94850/2 "2006-05-16T17:23:22Z")

</div>

On Tue, 16 May 2006, Berger, Daniel wrote:

> Just ARGV, I’m afraid. I suppose you could push args onto ARGV directly as  
> a workaround.
> 
> May I ask when you would want to parse an arbitrary array? I’m curious.

most of my standalone production code looks like this

~ \> cat foo

module Foo  
class Main  
…  
end  
end

Foo::Main.run(ARGV, ENV) if **FILE** == $0

that way foo runs as a script. however the code can be re-used in this  
way  
too

~ \> cat bar

require ‘foo’

module Bar  
class Main \< Foo::Main  
argv \<\< ‘–foo-option=42’  
env[‘foo\_env’] = 42  
super(argv, env)  
end  
end

Bar::Main.run(ARGV, ENV) if **FILE** == $0

or

foo = Foo::Main.new ‘–key=val --k2-v2’

etc.

basically i re-use top-level code as libs sometimes and then it’s  
important  
that two bits of code aren’t fighting over ARGV/ENV.

> Oh, and when I said, “Yes, it sucks”, I was referring to getoptlong in  
> the stdlib, not your code in particular. Just thought I should clarify  
> that. 🙂

either way - no offense taken!

cheers.

-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, 5:26pm UTC](https://www.ruby-forum.com/t/re-getoptlong-accessing-the-values-with-out-looping/94850/3 "2006-05-16T17:26:48Z")

</div>

On May 16, 2006, at 4:51 PM, Berger, Daniel wrote:

> Just ARGV, I’m afraid. I suppose you could push args onto ARGV  
> directly  
> as a workaround.
> 
> May I ask when you would want to parse an arbitrary array? I’m  
> curious.

Easier to write unit tests for, maybe.

– Daniel
