ARGV || something

ARGV || something

Post by Bil Kle » Sun, 10 Oct 2004 10:46:24


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, *** ia
http://www.yqcomputer.com/
 
 
 

ARGV || something

Post by T. Ono » Sun, 10 Oct 2004 12:14:52


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

-- ( o _ ?// trans./ \ XXXX@XXXXX.COM
I don't give a damn for a man that can only spell a word one way.-Mark Twain

 
 
 

ARGV || something

Post by Marku » Sun, 10 Oct 2004 12:38:43


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
 
 
 

ARGV || something

Post by Brian Cand » Sun, 10 Oct 2004 18:47:17


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

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

would do?
 
 
 

ARGV || something

Post by Robert Kle » Sun, 10 Oct 2004 21:56:48


"Bil Kleb" < XXXX@XXXXX.COM > schrieb im Newsbeitrag


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
 
 
 

ARGV || something

Post by rcode » Mon, 11 Oct 2004 07:20:08

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

ARGV || something

Post by Bil Kle » Wed, 13 Oct 2004 18:54:12


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, *** ia
 
 
 

ARGV || something

Post by Hal Fulto » Wed, 13 Oct 2004 23:55:41


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