在这段代码中,我想根据代码提供的索引值来迭代我的数组,比如一次我想迭代并获得 ARGV[1] 第二次 ARGV[3] 的输出。
认为
ARGV = ["-f","abc","-x","-p","wer"]
#!/usr/bin/env ruby
@lenght = ARGV.length
@factory_config_xml = ""
@num = 0
if @lenght != 0
ARGV.each_with_index do |a , x|
@num = @num + 1
b = ARGV[@num]
if ((a == "-f") && !(b.match "-") )
@factory_config_xml = b
x += 1
@num = @num + 1
elsif ((a == "-x") && !(b.match "-") )
@factory_config_xml = b
x += 1
@num = @num + 1
elsif ((a == "-p") && !(b.match "-") )
@factory_config_xml = b
x += 1
@num = @num + 1
end
end
end
puts @factory_config_xml