This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
argfy /
| name | age | message | |
|---|---|---|---|
| |
ARGFy.rb | Fri Dec 05 18:09:36 -0800 2008 | |
| |
README.markdown | Fri Dec 05 18:09:36 -0800 2008 | |
| |
doc/ | Fri Dec 05 18:09:36 -0800 2008 | |
| |
sample.rb | Fri Dec 05 18:09:36 -0800 2008 | |
| |
test/ | Fri Nov 28 22:03:34 -0800 2008 |
README.markdown
ARGFy - a more flexible ARGF
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.
Advantages
Although it acts like a stream, ARGFy keeps more information
about the current input file. These internal attributes are:
- lineno - line number of the entire stream
- filelineno - line number of the current file
- filename - current file being processed
Documentation
There is RDoc Documentation.
Example
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. Here is
the included sample.rb script:
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
puts
An example usage on the included test files is:
shell> ruby sample.rb test/in1.txt test/in2.txt
test/in1.txt
------------
1: one
2: two
test/in2.txt
------------
1: alpha, beta, gamma
2: 0987654321
3:
4: NOT BLANK!
Contact
- Author: Joseph Pecoraro (email)
- Website: http://blog.bogojoker.com
- Copyright: Copyright (c) 2008 Joseph Pecoraro
- License: Distributes under the same terms as Ruby







