[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ARGV || something

Bil Kleb

10/9/2004 1:46:00 AM

Hello.

I used to do this with VERSION < 1.8,

components = ARGV || %w[ Adjoint Design FUN3D_90 GetGrad
GridMove HRefine LibF90 Mixed Party
PHYSICS_MODULES Rad ]

It no longer works for VERSION == 1.8.2-p2.

What's going on and what is the idiom now?

I went through Why's 1.8 guide, but nothing slapped me.

Thanks,
--
Bil Kleb, Hampton, Virginia
http://fun3d.lar...


8 Answers

Ara.T.Howard

10/9/2004 2:50:00 AM

0

T. Onoma

10/9/2004 3:15:00 AM

0

On Friday 08 October 2004 10:54 pm, Ara.T.Howard@noaa.gov wrote:| components = ARGV || %w[ Adjoint Design FUN3D_90 GetGrad|| >                          GridMove HRefine LibF90 Mixed Party| >                          PHYSICS_MODULES Rad ]
although not perfectly DRY:
components = ARGV[0] ? ARGV : %w[ Adjoint Design FUN3D_90 GetGrad                    GridMove HRefine LibF90 Mixed Party                    PHYSICS_MODULES Rad ]

-- ( o _ ��� // trans./ \ transami@runbox.com
I don't give a damn for a man that can only spell a word one way.-Mark Twain

Markus

10/9/2004 3:39:00 AM

0

> On Sat, 9 Oct 2004, Bil Kleb wrote:
>
> > I used to do this with VERSION < 1.8,
> >
> > components = ARGV || %w[ Adjoint Design FUN3D_90 GetGrad
> > GridMove HRefine LibF90 Mixed Party
> > PHYSICS_MODULES Rad ]
> >
> > It no longer works for VERSION == 1.8.2-p2.
> >
> > What's going on and what is the idiom now?

On Fri, 2004-10-08 at 19:54, Ara.T.Howard@noaa.gov wrote:
>
> i can't figure that it ever would have worked?
>
> jib:~ > /usr/bin/ruby -v
> ruby 1.6.8 (2002-12-24) [i386-linux-gnu]
>
> jib:~ > /usr/bin/ruby -e'p(ARGV || 42)'
> []
>
> jib:~ > /usr/bin/ruby -e'p(ARGV || 42)' 42
> ["42"]
>
> jib:~ > /usr/bin/ruby -e'p(ARGV)'
> []
>
> even in 1.6.8 ARGV is an Array, and so always true? you have code that gives
> default arguments like this?

Are you sure you weren't doing something like:

components = *ARGV
components ||= %w[ Adjoint Design FUN3D_90 GetGrad
GridMove HRefine LibF90 Mixed Party
PHYSICS_MODULES Rad ]

(which I think should still work).

-- Markus



Brian Candler

10/9/2004 9:47:00 AM

0

On Sat, Oct 09, 2004 at 10:46:24AM +0900, Bil Kleb wrote:
> Hello.
>
> I used to do this with VERSION < 1.8,
>
> components = ARGV || %w[ Adjoint Design FUN3D_90 GetGrad
> GridMove HRefine LibF90 Mixed Party
> PHYSICS_MODULES Rad ]
>
> It no longer works for VERSION == 1.8.2-p2.
>
> What's going on and what is the idiom now?

I don't see how it would have worked before, but perhaps

components = ARGV
components = %w[...] if components.empty?

would do?


Robert Klemme

10/9/2004 12:57:00 PM

0


"Bil Kleb" <Bil.Kleb@NASA.Gov> schrieb im Newsbeitrag
news:416742E6.5060606@NASA.Gov...
> Hello.
>
> I used to do this with VERSION < 1.8,
>
> components = ARGV || %w[ Adjoint Design FUN3D_90 GetGrad
> GridMove HRefine LibF90 Mixed Party
> PHYSICS_MODULES Rad ]

As others I don't think this has ever worked. The cleanest idiom for me is
this:

components = ARGV.empty? ? %w[ Adjoint Design FUN3D_90 GetGrad
GridMove HRefine LibF90 Mixed Party
PHYSICS_MODULES Rad ] : ARGV

Kind regards

robert

rcoder@gmail.com

10/9/2004 10:20:00 PM

0

In Ruby 1.8, ARGV is always an array. Since the truth value of an empty
array is still "true", you can't just use '||' to provide defaults.

It's a bit longer, but your code should work if you do the following:

components = (ARGV.size > 0 ? ARGV : %w[ Adjoint Design UN3D_90 GetGrad
GridMove HRefine LibF90 Mixed Party PHYSICS_MODULES Rad ])
--
Lennon
rcoder.net

Bil Kleb

10/12/2004 9:54:00 AM

0

Ara.T.Howard@noaa.gov wrote:
> On Sat, 9 Oct 2004, Bil Kleb wrote:
>> I used to do this with VERSION < 1.8,
>>
>> components = ARGV || %w[ Adjoint Design FUN3D_90 GetGrad
>> GridMove HRefine LibF90 Mixed Party
>> PHYSICS_MODULES Rad ]
>
> even in 1.6.8 ARGV is an Array, and so always true? you have code that
> gives default arguments like this?

I thought I did, but upon some CVS log checking, this bit of
code just snuck in and this "option" was never actually put
to the test, i.e., used.

Thanks everyone for suggestions that actually work. :)

Regards,
--
Bil Kleb, Hampton, Virginia


Hal E. Fulton

10/12/2004 2:56:00 PM

0

Bil Kleb wrote:
> Ara.T.Howard@noaa.gov wrote:
>
>> On Sat, 9 Oct 2004, Bil Kleb wrote:
>>
>>> I used to do this with VERSION < 1.8,
>>>
>>> components = ARGV || %w[ Adjoint Design FUN3D_90 GetGrad
>>> GridMove HRefine LibF90 Mixed Party
>>> PHYSICS_MODULES Rad ]
>>
>>
>> even in 1.6.8 ARGV is an Array, and so always true? you have code
>> that gives default arguments like this?
>
>
> I thought I did, but upon some CVS log checking, this bit of
> code just snuck in and this "option" was never actually put
> to the test, i.e., used.
>
> Thanks everyone for suggestions that actually work. :)

Maybe you meant to say: ARGV[0] || stuff

That would work, though it's a little clunky. I probably
even recommended it in my earlier days... ;)


Hal