Jim Freeze <jim / freeze.org> 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