"John Baker" <mrjdoh / mailbox.co.za> writes:

> I've tried the following code on Win XP, Ruby 1.8rc1 and
> Mac OS X 10.3, Ruby 1.6.8. From the online documentation I
> pretty much copied and tried the following code:
>
> f = File.new("testfile.txt")
> puts f.gets                  >> This is line 1
> puts f.gets                  >> This is line 2
> f.lineno = 9                 >>
> puts f.lineno                >> 9
> puts f.gets                  >> This is line 3
>
> Although f.lineno updates to 9, it never seems to affect
> the line number next read.

IO#lineno= just sets the counter, not the position in the file.  This
is demonstrated in the ri example:

------------------------------------------------------------- IO#lineno=
     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