[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

ARGV question

Joe Johnson

10/19/2003 3:29:00 PM

I don't understand why since ARGV (the global command line argument
array) doesn't have the $ at the front as $ARGV since it's a global
variable? This looks inconsistent to me since Ruby requires all global
variables to begin with $. Can anyone please clarify this? TIA.

2 Answers

gabriele renzi

10/19/2003 8:01:00 PM

0

il Sun, 19 Oct 2003 08:29:07 -0700, Joe Johnson
<joejohnson1111@hotmail.com> ha scritto::

>I don't understand why since ARGV (the global command line argument
>array) doesn't have the $ at the front as $ARGV since it's a global
>variable? This looks inconsistent to me since Ruby requires all global
>variables to begin with $. Can anyone please clarify this? TIA.

It is a constant, not a variable.

Robert Klemme

10/19/2003 8:20:00 PM

0


"Joe Johnson" <joejohnson1111@hotmail.com> schrieb im Newsbeitrag
news:75ykb.94245$gv5.24856@fed1read05...
> I don't understand why since ARGV (the global command line argument
> array) doesn't have the $ at the front as $ARGV since it's a global
> variable? This looks inconsistent to me since Ruby requires all global
> variables to begin with $. Can anyone please clarify this? TIA.

I think, it's a constant in class Object and thus inherited by all objects.
Since you're always in the context of *some* instance you always can access
ARGV unqualified, i.e., use "ARGV" instead of "Object::ARGV".

>> $GLOBAL = "GGG"
=> "GGG"
>>
?> class Foo
>> ARGV='XXX'
>> $GLOBAL = "FFF"
>>
?> def arg; ARGV; end
>> def foo; $GLOBAL; end
>> end
=> nil
>>
?> class Bar < Foo
>> def bar; ARGV; end
>> end
=> nil
>>
?> Object::ARGV
=> []
>> Foo::ARGV
=> "XXX"
>> Bar::ARGV
=> "XXX"
>>
?> Foo.new.arg
=> "XXX"
>> Foo.new.foo
=> "FFF"
>> Bar.new.arg
=> "XXX"
>> Bar.new.foo
=> "FFF"
>> $GLOBAL
=> "FFF"
>> Object::$GLOBAL
SyntaxError: compile error
(irb):24: syntax error
from (irb):24
>>

Regards

robert