Ruby 中的 ARGV 有什么意义?
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}"
什么时候运行我需要做的文件有什么意义:
ruby ex1.rb
并输入我需要输入的第一个、第二个和第三个变量
ruby ex1.rb blah blah blah
这对所有运行程序的人有什么好处?他们无论如何都做不到,因为我认为它是一个可执行文件:
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
有人可以向我解释一下吗?