Method: ARGF#getc
- Defined in:
- io.c
#getc ⇒ String?
Reads the next character from ARGF and returns it as a String. Returns nil at the end of the stream.
ARGF treats the files named on the command line as a single file created by concatenating their contents. After returning the last character of the first file, it returns the first character of the second file, and so on.
For example:
$ echo "foo" > file
$ ruby argf.rb file
ARGF.getc #=> "f"
ARGF.getc #=> "o"
ARGF.getc #=> "o"
ARGF.getc #=> "\n"
ARGF.getc #=> nil
ARGF.getc #=> nil
14038 14039 14040 14041 14042 14043 14044 14045 14046 14047 14048 14049 14050 14051 14052 14053 14054 14055 14056 14057 14058 |
# File 'io.c', line 14038
static VALUE
argf_getc(VALUE argf)
{
VALUE ch;
retry:
if (!next_argv()) return Qnil;
if (ARGF_GENERIC_INPUT_P()) {
ch = forward_current(rb_intern("getc"), 0, 0);
}
else {
ch = rb_io_getc(ARGF.current_file);
}
if (NIL_P(ch) && ARGF.next_p != -1) {
argf_close(argf);
ARGF.next_p = 1;
goto retry;
}
return ch;
}
|