Argc *argv[] in Ruby

Hello,
Does Ruby have something like C has argc and *argv[]?
I need to run ruby script with a command line parameters.

Thanks in advance for any helpfull answer.

···

--
RaW

ARGV holds an array of command line parameters. There's no argc, but you can
just use ARVG.length.

Oh, one more thing: Unlike argv in C/C++, in Ruby ARVG[0] will contain the
first argument passed in to the program, not the program name. If you want
the name of script, use the global variable $0.

Chris Eskow wrote:

Oh, one more thing: Unlike argv in C/C++, in Ruby ARVG[0] will
contain the first argument passed in to the program, not the program
name. If you want the name of script, use the global variable $0.

Adding to that there's also ARGF which is a single IO like object that
reads from all command line named files:

# poor man's cat
# this works even without any arguments by
# reading from STDIN
ARGF.each_line {|line| puts line}

And while we're at it, there are also two libs for option processing:

http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/index.html
http://www.ruby-doc.org/stdlib/libdoc/getoptlong/rdoc/index.html

I recommend OptionParser as it seems more flexible and also has very nice
help output generation.

Kind regards

    robert