ARGV || something

B

Bil Kleb

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,
 
A

Ara.T.Howard

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.

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
--
===============================================================================
| 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
===============================================================================
 
T

trans. (T. Onoma)

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

-- ( o _ カラム// trans./ \ (e-mail address removed)
I don't give a damn for a man that can only spell a word one way.-Mark Twain
 
M

Markus

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

Brian Candler

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?
 
R

Robert Klemme

Bil Kleb said:
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
 
R

rcoder

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 ])
 
B

Bil Kleb

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,
 
H

Hal Fulton

Bil said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,881
Members
47,418
Latest member
NoellaXku

Latest Threads

Top