| Path: | ARGFy.rb |
| Last Update: | Fri Dec 05 21:08:31 -0500 2008 |
This class is a more flexible version of the ARGF global. The constructor takes an array, a list of files, and processes them like one constant stream of input. Reading from the stream is always line by line either all at once using each or one at a time using gets.
Internal states can help your program understand what was processed when you pull any line:
This is a simple program that prints out each file with a simple header when the input files change. It shows the main advantage of this class over ARGF.
require 'ARGFy'
argf = ARGFy.new(ARGV)
argf.each do |line|
# Per File Header
if argf.new_file?
filename = argf.filename
filename = "STDIN" if filename == "-"
puts '', filename, "-"*filename.length
end
# Print out the line with line numbers
puts "%3d: %s" % [argf.filelineno, line]
end
| Author: | Joseph Pecoraro (joepeck02@gmail.com) |
| Copyright: | Copyright © 2008 Joseph Pecoraro |
| License: | Distributes under the same terms as Ruby |