ARGV在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}"
Run Code Online (Sandbox Code Playgroud)
在运行我需要做的文件时,重点是什么:
ruby ex1.rb
Run Code Online (Sandbox Code Playgroud)
并输入我需要输入的第一,第二和第三个变量
ruby ex1.rb blah blah blah
Run Code Online (Sandbox Code Playgroud)
这对所有运行程序的人有什么好处?他们无论如何都做不到,因为我认为它是一个可执行文件:
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}?" …Run Code Online (Sandbox Code Playgroud) 要使用MySQL创建Rails应用程序,我执行以下操作:
rails new application -database=mysql
Run Code Online (Sandbox Code Playgroud)
但这不起作用,而是它给了我的SQLite.我不想要SQLite,我想要MySQL.
我怎么解决这个问题?