ARGV || something

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.larc.nasa.gov

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?

regards

-a

···

On Sat, 9 Oct 2004, 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 went through Why's 1.8 guide, but nothing slapped me.

--

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
A flower falls, even though we love it;
and a weed grows, even though we do not love it. --Dogen

===============================================================================

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

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

would do?

···

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?

"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

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

although not perfectly DRY:

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

···

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 ]

--
( o _ カラチ
// trans.
/ \ transami@runbox.com

I don't give a damn for a man that can only spell a word one way.
-Mark Twain

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

···

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?

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

Regards,

···

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?

--
Bil Kleb, Hampton, Virginia

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

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

Hal