From: dblack@... Date: 2002-10-24T20:04:23+09:00 Subject: Re: Read "current line" from a file? Hi -- On Thu, 24 Oct 2002, Gavin Sinclair wrote: > All, > > Given an IO object, you can get the "next" line with #gets, right? > > Given an IO object, you can get the "current" line with #X, right? Please? > > I know it's not a common operation, but I would like tobe able to do it. Do you mean a kind of one-line lookahead? I had occasion to do that somewhere recently, and did: class File def ungets(str) seek(pos - str.size,0) end # One-line lookahead. def next_line line = gets ungets(line) if line line end end David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav