On Sat, Nov 15, 2008 at 2:08 PM, Chad Perrin <perrin / apotheon.com> wrote:
> On Sun, Nov 16, 2008 at 02:27:45AM +0900, Tim Hunter wrote:
>>
>> The way I read the ri doc for lineno=, it appears that all it does is
>> determine the value that lineno returns the next time you call it. That
>> is, it doesn't move the read position in the file.
>
> I think you're confusing lineno= with lineno (which are two separate
> methods).  IO#lineno does this:
>
>    ios.lineno
>    => 0
>
> IO#lineno= does this:
>
>    ios.lineno = 3
>    => 3
>
> The class is specced here, with the screen scrolled to where IO#lineno
> and IO#lineno= are listed:
>
>    http://ruby-doc.org/core/classes/IO.html#M002289
>
>
>>
The description of the method is somewhat ambiguous if you ask me.

My view of the docs is inline with what Tim was describing.

------------------------------------------------------------- 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


I would think if it had the behavior you described, the second time
f.gets is called, we would see: "This is line one thousand and one\n"
not "This is line two\n"

Michael Guterl