public Method

IO.lineno=(p1)

ios.lineno = integer     integer

Manually sets the current line number to the given value. $. is updated only on the next read.

f = File.new("testfile")
f.gets                     #=> "This is line one\n"
$.                         #=> 1
f.lineno = 1000
f.lineno                   #=> 1000
$. # lineno of last read   #=> 1
f.gets                     #=> "This is line two\n"
$. # lineno of last read   #=> 1001

Source Code

/*
*  call-seq:
*     ios.lineno = integer    => integer
*  
*  Manually sets the current line number to the given value.
*  <code>$.</code> is updated only on the next read.
*     
*     f = File.new("testfile")
*     f.gets                     #=> "This is line one\n"
*     $.                         #=> 1
*     f.lineno = 1000
*     f.lineno                   #=> 1000
*     $. # lineno of last read   #=> 1
*     f.gets                     #=> "This is line two\n"
*     $. # lineno of last read   #=> 1001
*/

static VALUE
rb_io_set_lineno(io, lineno)
   VALUE io, lineno;
{
   OpenFile *fptr;

   GetOpenFile(io, fptr);
   rb_io_check_readable(fptr);
   fptr->lineno = NUM2INT(lineno);
   return lineno;
}
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.