ARGV
In this page:
ARGV
ARGV is a global array holding the command-line arguments passed to a Ruby script when it's run, excluding the script name itself. ARGV[0] is the first argument, ARGV.length gives the count, and so on -- it behaves just like a normal array. This is the standard way a Ruby script reads input passed to it from the command line.
Note: ARGV always contains strings, even if an argument looks numeric -- convert with .to_i or .to_f if you need a number.
Example: ARGV
# Simulating ARGV since this runs without real command-line arguments:
simulated_argv = ["report.txt", "--verbose"]
puts "Argument count: #{simulated_argv.length}"
puts "First argument: #{simulated_argv[0]}"
puts "In a real script, this data comes from the built-in ARGV array"
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: