/* * call-seq: * gets(separator=$/) => string or nil * * Returns (and assigns to <code>$_</code>) the next line from the list * of files in +ARGV+ (or <code>$*</code>), or from standard * input if no files are present on the command line. Returns * +nil+ at end of file. The optional argument specifies the * record separator. The separator is included with the contents of * each record. A separator of +nil+ reads the entire * contents, and a zero-length separator reads the input one paragraph * at a time, where paragraphs are divided by two consecutive newlines. * If multiple filenames are present in +ARGV+, * +gets(nil)+ will read the contents one file at a time. * * ARGV << "testfile" * print while gets * * <em>produces:</em> * * This is line one * This is line two * This is line three * And so on... * * The style of programming using <code>$_</code> as an implicit * parameter is gradually losing favor in the Ruby community. */ static VALUE rb_f_gets(argc, argv) int argc; VALUE *argv; { VALUE line; if (!next_argv()) return Qnil; if (TYPE(current_file) != T_FILE) { line = rb_funcall3(current_file, rb_intern("gets"), argc, argv); } else { line = argf_getline(argc, argv); } rb_lastline_set(line); return line; }