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