Method: File.open

Defined in:
io.c

.open(filename, mode = "r"[, opt]) ⇒ File .open(filename[, mode [, perm]][, opt]) ⇒ File .open(filename, mode = "r"[, opt]) {|file| ... } ⇒ Object .open(filename[, mode [, perm]][, opt]) {|file| ... } ⇒ Object

With no associated block, open is a synonym for File.new. If the optional code block is given, it will be passed file as an argument, and the File object will automatically be closed when the block terminates. In this instance, File.open returns the value of the block.

Overloads:

  • .open(filename, mode = "r"[, opt]) ⇒ File

    Returns:

  • .open(filename[, mode [, perm]][, opt]) ⇒ File

    Returns:

  • .open(filename, mode = "r"[, opt]) {|file| ... } ⇒ Object

    Yields:

    • (file)

    Returns:

  • .open(filename[, mode [, perm]][, opt]) {|file| ... } ⇒ Object

    Yields:

    • (file)

    Returns:



# File 'io.c'

/*
 *  Document-method: IO::open
 *
 *  call-seq:
 *     IO.open(fd, mode_string="r" [, opt] )               -> io
 *     IO.open(fd, mode_string="r" [, opt] ) {|io| block } -> obj
 *
 *  With no associated block, <code>open</code> is a synonym for
 *  <code>IO.new</code>. If the optional code block is given, it will
 *  be passed <i>io</i> as an argument, and the IO object will
 *  automatically be closed when the block terminates. In this instance,
 *  <code>IO.open</code> returns the value of the block.
 *
 */

static VALUE
rb_io_s_open(int argc, VALUE *argv, VALUE klass)
{
    VALUE io = rb_class_new_instance(argc, argv, klass);

    if (rb_block_given_p()) {
    return rb_ensure(rb_yield, io, io_close, io);
    }

    return io;
}