Top Level Namespace

Defined Under Namespace

Modules: Comparable, Enumerable, Errno, FileTest, GC, Kernel, Marshal, Math, ObjectSpace, Precision, Process, Signal Classes: ArgumentError, Array, Bignum, Binding, Class, Continuation, Data, Dir, EOFError, Exception, FalseClass, File, Fixnum, Float, FloatDomainError, Hash, IO, IOError, IndexError, Integer, Interrupt, LoadError, LocalJumpError, MatchData, Method, Module, NameError, NilClass, NoMemoryError, NoMethodError, NotImplementedError, Numeric, Object, Proc, Range, RangeError, Regexp, RegexpError, RuntimeError, ScriptError, SecurityError, SignalException, StandardError, StopIteration, String, Struct, Symbol, SyntaxError, SystemCallError, SystemExit, SystemStackError, Thread, ThreadError, ThreadGroup, Time, TrueClass, TypeError, UnboundMethod, ZeroDivisionError, fatal

Class Method Summary collapse

Class Method Details

.binmodeObject

.bytesObject

.charsObject

.closeObject

.closed?Boolean

Returns:

  • (Boolean)

.eachObject

.each_byteObject

.each_charObject

.each_lineObject

.eofObject

.eof?Boolean

Returns:

  • (Boolean)

.fileObject

.filenameObject

.filenoObject

.getbyteObject

.getcObject

.gets(separator = $/) ⇒ String?

Returns (and assigns to $_) the next line from the list of files in ARGV (or $*), 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

produces:

This is line one
This is line two
This is line three
And so on...

The style of programming using $_ as an implicit parameter is gradually losing favor in the Ruby community.

Returns:



# File 'io.c'

/*
 *  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;
}

.induced_from(number) ⇒ Object

Creates an instance of mod from. This method is overridden by concrete Numeric classes, so that (for example)

Fixnum.induced_from(9.9)   #=>  9

Note that a use of prec in a redefinition may cause an infinite loop.



# File 'prec.c'

/*
 * call-seq:
 *   Mod.induced_from(number)  =>  a_mod
 * 
 * Creates an instance of mod from. This method is overridden
 * by concrete +Numeric+ classes, so that (for example)
 *
 *   Fixnum.induced_from(9.9)   #=>  9
 *
 * Note that a use of +prec+ in a redefinition may cause
 * an infinite loop.
 */

static VALUE
prec_induced_from(module, x)
    VALUE module, x;
{
    rb_raise(rb_eTypeError, "undefined conversion from %s into %s",
            rb_obj_classname(x), rb_class2name(module));
    return Qnil;        /* not reached */
}

.linenoObject

.lineno=Object

.linesObject

.pathObject

.posObject

.pos=Object

.readObject

.readbyteObject

.readcharObject

.readline(separator = $/) ⇒ String

Equivalent to Kernel::gets, except readline raises EOFError at end of file.

Returns:



# File 'io.c'

/*
 *  call-seq:
 *     readline(separator=$/)   => string
 *  
 *  Equivalent to <code>Kernel::gets</code>, except
 *  +readline+ raises +EOFError+ at end of file.
 */

static VALUE
rb_f_readline(argc, argv)
    int argc;
    VALUE *argv;
{
    VALUE line;

    if (!next_argv()) rb_eof_error();
    ARGF_FORWARD(argc, argv);
    line = rb_f_gets(argc, argv);
    if (NIL_P(line)) {
    rb_eof_error();
    }

    return line;
}

.readlines(separator = $/) ⇒ Array

Returns an array containing the lines returned by calling Kernel.gets(separator) until the end of file.

Returns:



# File 'io.c'

/*
 *  call-seq:
 *     readlines(separator=$/)    => array
 *  
 *  Returns an array containing the lines returned by calling
 *  <code>Kernel.gets(<i>separator</i>)</code> until the end of file.
 */

static VALUE
rb_f_readlines(argc, argv)
    int argc;
    VALUE *argv;
{
    VALUE line, ary;

    NEXT_ARGF_FORWARD(argc, argv);
    ary = rb_ary_new();
    while (!NIL_P(line = argf_getline(argc, argv))) {
    rb_ary_push(ary, line);
    }

    return ary;
}

.rewindObject

.seekObject

.skipObject

.tellObject

.readlines(separator = $/) ⇒ Array

Returns an array containing the lines returned by calling Kernel.gets(separator) until the end of file.

Returns:



# File 'io.c'

/*
 *  call-seq:
 *     readlines(separator=$/)    => array
 *  
 *  Returns an array containing the lines returned by calling
 *  <code>Kernel.gets(<i>separator</i>)</code> until the end of file.
 */

static VALUE
rb_f_readlines(argc, argv)
    int argc;
    VALUE *argv;
{
    VALUE line, ary;

    NEXT_ARGF_FORWARD(argc, argv);
    ary = rb_ary_new();
    while (!NIL_P(line = argf_getline(argc, argv))) {
    rb_ary_push(ary, line);
    }

    return ary;
}

.to_iObject

.to_ioObject

.to_sObject