From: raja@... (Raja S.) Date: 2001-04-21T10:11:24+09:00 Subject: [ruby-talk:13951] Re: Is it possible to unread a line? Jim Freeze writes: >Is it possible to 'un'readline? >I have a file that has possible line continuations. >I can only know if a line is continued by reading the >next line and checking for /^\+/. If it is there, then >the line is continued. You could subclass (or extend) File with a buffer, extend #readline and write #unreadline along the following lines: # unreadline.rb class File alias :old_initialize :initialize alias :old_readline :readline def initialize (*args) @buf=[] old_initialize(*args) end def unreadline (str) @buf.push(str) end def readline (*args) @buf.empty? ? old_readline(*args) : @buf.pop end end Regards, Raja