Was bringt ARGV in Ruby?

Was bringt ARGV in Ruby?

first, second, third = ARGV 
puts "The script is called: #{$0}"
puts "Your first variable is: #{first}"
puts "Your second variable is: #{second}"
puts "Your third variable is: #{third}"

Was ist der Sinn davon, wenn ich die Datei ausführen muss:

ruby ex1.rb

und um die erste, zweite und dritte Variable einzugeben, muss ich eingeben

ruby ex1.rb blah blah blah

Inwiefern kommt dies der Person zugute, die das Programm durchführt? Sie können es sowieso nicht tun, da ich davon ausgehen würde, dass es eine ausführbare Datei ist:

user = ARGV.first
prompt = '> '

puts "Hi #{user}, I'm the #{$0} script."
puts "I'd like to ask you a few questions."
puts "Do you like me #{user}?"
print prompt
likes = STDIN.gets.chomp()

puts "Where do you live #{user}?"
print prompt
lives = STDIN.gets.chomp()

puts "What kind of computer do you have?"
print prompt
computer = STDIN.gets.chomp()

puts <<MESSAGE
Alright, so you said #{likes} about liking me.
You live in #{lives}.  Not sure where that is.
And you have a #{computer} computer.  Nice.
MESSAGE

Kann mir das bitte jemand erklären?

Antworten auf die Frage(5)

Ihre Antwort auf die Frage