title: ruby - how to correctly parse varying numbers of command line arguments
body: <p>n00b question alert!
  here is the problem: 
  I am creating a shell script that takes a minimum of 3 arguments: a string, a line number, and at least one file.</p>
  
  <p>I've written a script that will accept EXACTLY 3 arguments, but I don't know how to handle multiple file name arguments.</p>
  
  <p>here's the relevant parts of my code (skipping the writing back into the file etc):</p>
  
  <pre><code>#!/usr/bin/env ruby
  
  the_string = ARGV[0] 
  line_number = ARGV[1]
  the_file = ARGV[2] 
  
  def insert_script(str, line_n, file)
    f = file
    s = str
    ln = line_n.to_i
  
    if (File.file? f)
      read_in(f,ln,s)
    else 
      puts "false"
    end
  end
  
  def read_in(f,ln,s)
    lines = File.readlines(f)
    lines[ln] = s + "\n"
    return lines
  end
  
  # run it
  puts insert_script(the_string, line_number, the_file)
  </code></pre>
  
  <p>now I know that it's easy to write a block that will iterate through ALL the arguments:</p>
  
  <pre><code>ARGV.each do |a|
     puts a 
  end
  </code></pre>
  
  <p>but I need to ONLY loop through the args from ARGV[2] (the first file name) to the last file name. </p>
  
  <p>I know there's got to be - at a minimum - at least one easy way to do this, but I just can't see what it is at the moment! </p>
  
  <p>in any case - I'd be more than happy if someone can just point me to a tutorial or an example, I'm sure there are plenty out there - but I can't seem to find them. </p>
  
  <p>thanks</p>