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, String, Struct, Symbol, SyntaxError, SystemCallError, SystemExit, SystemStackError, Thread, ThreadError, ThreadGroup, Time, TrueClass, TypeError, UnboundMethod, ZeroDivisionError, fatal

Class Method Summary collapse

Class Method Details

.binmodeObject

.closeObject

.closed?Boolean

Returns:

  • (Boolean)

.eachObject

.each_byteObject

.each_lineObject

.eofObject

.eof?Boolean

Returns:

  • (Boolean)

.fileObject

.filenameObject

.filenoObject

.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'

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);
}

.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'

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

.pathObject

.posObject

.pos=Object

.readObject

.readcharObject

.readline(separator = $/) ⇒ String

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

Returns:



# File 'io.c'

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();
}

.readlines(separator = $/) ⇒ Array

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

Returns:



# File 'io.c'

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);
}

.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'

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);
}

.to_iObject

.to_ioObject

.to_sObject