What does this line in Ruby : Input_file = ARGV.first mean ?
ARGV
is the arguments given to the Ruby script.
E.g., if you have a script myscript.rb
and run it with:
$ ruby myscript.rb 1 2 3
then ARGV
will contain 1
, 2
, and 3
.
The first argument of ARGV
is however always the script’s name itself. So doing
input_file = ARGV.first
will give you the name of the current file in the input_file
-variable.
Hmm , a little confused about this — could you give a concrete example?
So let’s say I create a new file called myscript.rb, save it one of my folders, then I run the command ----- $ ruby myscript.rb 1 2 3, then ARGC will contain 1, 2 and 3 ?
If you could show a screenshot of the steps, it would be clearer lol.
That is because I was wrong. The first argument of ARGV
isn’t the filename (it is in some other programming languages)
An example you can look at is this file (save it and call it myscript.rb
):
puts "The current file is: #{File.basename __FILE__}"
puts "You ran the script with the following arguments: #{ARGV}"
running this with:
$ ruby myscript.rb 1 2 3
will return
The current file is: myscript.rb
You ran the script with the following arguments: ["1", "2", "3"]
Oh ok, so for the question — “Write English comments for each line to understand what that line does.” , what should I write beside the line Input_file = ARGV.first ?
Thanks alot …