GetoptLong#to_hash

From: Gavin Sinclair [mailto:gsinclair@soyabean.com.au]
Sent: Friday, August 02, 2002 12:16 AM
To: ruby-talk@ruby-lang.org
Subject: Re: GetoptLong#to_hash

That doesn’t sound like a great idea to me, unless all the
methods of Hash
are useful in an “options” context. (They may well be; I’ve
had very small
exposure to GetoptLong.)

I disagree. Why must all the options be useful? I’m sure more than one
person here has subclassed a base class where we never really expect to use
methods x, y and z. Not that they wouldn’t work, you just wouldn’t use
them.

As it stands now, GetoptLong acts like a cousin of Hash, rather than a
child. Looks like a Hash, smells like a Hash but…it’s not a Hash. This
only leads to confusion, IMHO. Besides, it already sounds like more than
one person is resolving their problems with GetoptLong by slapping the
results into a Hash anyway. I know I have.

I guess I’m at the .03 cent stage now. :slight_smile:

Regards,

Dan

···

-----Original Message-----

I’m just saying this because Java made a hash (ha ha) of
their original
Stack class be extending Vector. Simply wrong.

Cheers,
Gavin

----- Original Message -----
From: “Berger, Daniel” djberge@qwest.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, August 01, 2002 10:24 PM
Subject: RE: GetoptLong#to_hash

-----Original Message-----
From: Pit Capitain [mailto:pit@capitain.de]
Sent: Thursday, August 01, 2002 2:39 AM
To: ruby-talk@ruby-lang.org
Subject: Re: GetoptLong#to_hash

On 1 Aug 2002, at 15:41, Paul Duncan wrote:

I find myself converting the results of option parsing into
a hash.

Let’s take it a step further. Scrap the current
implementation and make
GetoptLong a subclass of Hash.

Just my .02.

Regards,

Dan

As it stands now, GetoptLong acts like a cousin of Hash, rather than a
child. Looks like a Hash, smells like a Hash but…it’s not a Hash. This
only leads to confusion, IMHO. Besides, it already sounds like more than

Doesn’t it need to be an ordered hash, for the case where successive
options override earlier ones?

Regards,

Dan

    Hugh
···

On Fri, 2 Aug 2002, Berger, Daniel wrote:

Hi,

···

At Fri, 2 Aug 2002 20:44:42 +0900, Berger, Daniel djberge@qwest.com wrote:

As it stands now, GetoptLong acts like a cousin of Hash, rather than a
child. Looks like a Hash, smells like a Hash but…it’s not a Hash. This
only leads to confusion, IMHO. Besides, it already sounds like more than
one person is resolving their problems with GetoptLong by slapping the
results into a Hash anyway. I know I have.

GetoptLong doesn’t act like a Hash, but does as an Enumerable.


Nobu Nakada

Hugh Sasse Staff Elec Eng wrote:

···

On Fri, 2 Aug 2002, Berger, Daniel wrote:

As it stands now, GetoptLong acts like a cousin of Hash, rather than a
child. Looks like a Hash, smells like a Hash but…it’s not a Hash. This
only leads to confusion, IMHO. Besides, it already sounds like more than

Doesn’t it need to be an ordered hash, for the case where successive
options override earlier ones?

Regards,

Dan

   Hugh

Sounds like a tree is what you are really after. Or a hash that has
lists as members.


– Charles Hixson
Gnu software that is free,
The best is yet to be.

As it stands now, GetoptLong acts like a cousin of Hash, rather than a
child. Looks like a Hash, smells like a Hash but…it’s not a Hash. This
only leads to confusion, IMHO. Besides, it already sounds like more than

Doesn’t it need to be an ordered hash, for the case where successive
options override earlier ones?

The conversation here seems to be assuming I was talking about replacing
the existing implementation with something more hash-like. I wasn’t. A
hash wouldn’t account for the instance you just mentioned, nor would it
account for cases where one option negates another one (because there
would be no way to tell which came first on the command-line).

That said, I still believe it’s something that would be useful in the
base class. The #to_hash method I proposed would a convenient and
simple way to handle the most common case: a quick program with a few
non-related command-line options to choose from.

···

On Fri, 2 Aug 2002, Berger, Daniel wrote:

Regards,

Dan

    Hugh


Paul Duncan pabs@pablotron.org pabs in #gah (OPN IRC)
http://www.pablotron.org/ OpenPGP Key ID: 0x82C29562

Or an array of pairs (which can be generated from a hash, if necessary)

irb(main):001:0> x = { 1=>2, 2=>3, 3=>4 }
{1=>2, 2=>3, 3=>4}
irb(main):002:0> y = x.sort
[[1, 2], [2, 3], [3, 4]]
irb(main):003:0> y.assoc(2)
[2, 3]

Paul

···

On Sat, Aug 03, 2002 at 02:17:19AM +0900, Charles Hixson wrote:

Sounds like a tree is what you are really after. Or a hash that has
lists as members.