If you've tried to use ARGF in Ruby to accept piped input you might be in for a surprise when you attempt to add additional command-line arguments, such as:

$ cat something.log | your-ruby-program ~/outputfile.txt "some phrase"

Trying to read the ARGV arguments after using ARGF will cause your program to fail as it first attempts to open a file located at ~/outputfile.txt and read its contents - or even worse, succeed and not perform what you expect if such a file exists. Obviously not the desired goal.

Instead ARGV.shift can be used prior to invoking ARGF to peel those arguments off the argument stack:

  
#!/usr/bin/env ruby

output_path = ARGV.shift  
search_phrase = ARGV.shift

if ARGV.length > 2  
    limit = ARGV.shift
end

# now ARGF can be accessed without Ruby trying to automatically 
# read files named after the supplied arguments
data = ARGF.read

Found this out after a bit of digging on StackOverflow and its in the Ruby docs too.