public Method

IO.rewind

ios.rewind     0

Positions ios to the beginning of input, resetting lineno to zero.

f = File.new("testfile")
f.readline   #=> "This is line one\n"
f.rewind     #=> 0
f.lineno     #=> 0
f.readline   #=> "This is line one\n"

Source Code

/*
*  call-seq:
*     ios.rewind    => 0
*  
*  Positions <em>ios</em> to the beginning of input, resetting
*  <code>lineno</code> to zero.
*     
*     f = File.new("testfile")
*     f.readline   #=> "This is line one\n"
*     f.rewind     #=> 0
*     f.lineno     #=> 0
*     f.readline   #=> "This is line one\n"
*/

static VALUE
rb_io_rewind(io)
   VALUE io;
{
   OpenFile *fptr;

   GetOpenFile(io, fptr);
   if (io_seek(fptr, 0L, 0) != 0) rb_sys_fail(fptr->path);
   clearerr(fptr->f);
   if (io == current_file) {
       gets_lineno -= fptr->lineno;
   }
   fptr->lineno = 0;

   return INT2FIX(0);
}
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.