我试图让我的脚本根据选项做不同的事情。但是...我根本不知道红宝石。我什至不能告诉你数组到底是什么。这是我得到的:
require 'optparse'
require 'pp'
# the options eventually get put here
options = {}
optparse = OptionParser.new do|opts|
# the help info
opts.banner = "Usage: script.rb [options] input-file output-file"
# This sets the default of 'flag' to 'false' and says it should be
# 'true' if the '-f' option is present
options[:flag] = false
opts.on( '-f', '--flag', "Flag has been set" ) do
options[:flag] = true
end
end
optparse.parse!
# if no input-file or output-file is given, spit out the help
if ARGV.empty?
puts optparse
exit(-1)
end
# If the flag is true then tell me so, if not, tell me it isn't.
if options[:flag] = true
pp "Flag is true"
else
pp "Flag is false"
end
提前致谢,很抱歉在不知道如何编码的情况下尝试编码。我向你鞠躬哦,伟大的。