title: ruby array each_with_index
body: <p>In this code i want to iterate my array according to index value which is provided by code like one time i want to iterate and get output of ARGV[1] second time ARGV[3].</p>
  
  <p>suppose </p>
  
  <pre><code>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") &amp;&amp; !(b.match "-") )
  
              @factory_config_xml = b
              x += 1
              @num = @num + 1
  
          elsif ((a == "-x") &amp;&amp; !(b.match "-") )
  
              @factory_config_xml = b
              x += 1
              @num = @num + 1
  
          elsif ((a == "-p") &amp;&amp; !(b.match "-") )
  
              @factory_config_xml = b
              x += 1
              @num = @num + 1
          end
  
      end
  end
  
  
  puts @factory_config_xml 
  </code></pre>