method
getc
ruby latest stable - Class:
ARGF
getc()public
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
static VALUE
argf_getc(VALUE argf)
{
VALUE ch;
retry:
if (!next_argv()) return Qnil;
if (ARGF_GENERIC_INPUT_P()) {
ch = rb_funcall3(ARGF.current_file, 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;
}