Type:
Class

ARGF is a stream designed for use in scripts that process files given as command-line arguments or passed in via STDIN.

The arguments passed to your script are stored in the ARGV Array, one argument per element. ARGF assumes that any arguments that aren't filenames have been removed from ARGV. For example:

$ ruby argf.rb --verbose file1 file2

ARGV  #=> ["--verbose", "file1", "file2"]
option = ARGV.shift #=> "--verbose"
ARGV  #=> ["file1", "file2"]

You can now use ARGF to work with a concatenation of each of these named files. For instance, ARGF.read will return the contents of file1 followed by the contents of file2.

After a file in ARGV has been read ARGF removes it from the Array. Thus, after all files have been read ARGV will be empty.

You can manipulate ARGV yourself to control what ARGF operates on. If you remove a file from ARGV, it is ignored by ARGF; if you add files to ARGV, they are treated as if they were named on the command line. For example:

ARGV.replace ["file1"]
ARGF.readlines # Returns the contents of file1 as an Array
ARGV           #=> []
ARGV.replace ["file2", "file3"]
ARGF.read      # Returns the contents of file2 and file3

If ARGV is empty, ARGF acts as if it contained STDIN, i.e. the data piped to your script. For example:

$ echo "glark" | ruby -e 'p ARGF.read'
"glark\n"
each_byte

ARGF.bytes {|byte| block } â ARGFARGF.bytes â an_enumeratorARGF.each_byte {|byte| block } â ARGFARGF.each_byte

2015-03-30 10:58:36
inspect

inspect() Instance Public methods Alias for:

2015-03-30 11:44:45
getc

ARGF.getc â String or nil Instance Public methods Reads the next character

2015-03-30 11:30:12
to_s

ARGF.to_s â String Instance Public methods Returns âARGFâ.

2015-03-30 13:44:55
lineno

ARGF.lineno â integer Instance Public methods Returns the current line number

2015-03-30 11:56:46
print

ios.print() â nilios.print(obj, ...) â nil Instance Public methods

2015-03-30 12:24:01
skip

ARGF.skip â ARGF Instance Public methods Sets

2015-03-30 13:30:30
file

ARGF.file â IO or File object Instance Public methods Returns the current

2015-03-30 11:24:30
each

ARGF.each(sep=$/) {|line| block } â ARGFARGF.each(sep=$/,limit) {|line| block } â ARGFARGF.each(...)

2015-03-30 10:51:04
each_codepoint

ARGF.each_codepoint {|codepoint| block } â ARGFARGF.each_codepoint â an_enumerator Instance

2015-03-30 11:04:05