static public Method

IO.new(...)

IO.new(fd, mode_string)    io

Returns a new IO object (a stream) for the given integer file descriptor and mode string. See also IO#fileno and IO::for_fd.

a = IO.new(2,"w")      # '2' is standard error
$stderr.puts "Hello"
a.puts "World"

produces:

Hello
World

Source Code

/*
*  call-seq:
*     IO.new(fd, mode_string)   => io
*  
*  Returns a new <code>IO</code> object (a stream) for the given
*  integer file descriptor and mode string. See also
*  <code>IO#fileno</code> and <code>IO::for_fd</code>.
*     
*     a = IO.new(2,"w")      # '2' is standard error
*     $stderr.puts "Hello"
*     a.puts "World"
*     
*  <em>produces:</em>
*     
*     Hello
*     World
*/

static VALUE
rb_io_s_new(argc, argv, klass)
   int argc;
   VALUE *argv;
   VALUE klass;
{
   if (rb_block_given_p()) {
       char *cname = rb_class2name(klass);

       rb_warn("%s::new() does not take block; use %s::open() instead",
               cname, cname);
   }
   return rb_class_new_instance(argc, argv, klass);
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.