How does this argument variable work?

I’m new to Ruby, and was going through an example that started as
follows:

user = ARGV.first
puts “Hi #{user} , I’m the #{$0} script”

When I run the program with the following arguments: > ruby xyz.rb
SWEngineer

I got the following:

Hi SWEngineer, I’m the xyz script

I just want to ask, how did we get this output?

What does ARGV.first mean?

Does $0 get the content of ARGV?

Thanks.

hi

You are invoking “Pre-defined global constants” of Ruby

ARGV # An array of all the arguments given on run.

This is an array , while you run, it’s holding all argument of your
comment line, For an example,

#Program
puts ARGV[0]
puts ARGV[1]
puts ARGV[2]

Invoking interpreter with arguments

ruby hi.rb ‘raja’ ‘gopal’ ‘M’

output

raja
gopal
M

$0 is an another Global constant which always holding the file name.

Hope it helps.