# File lib/elif.rb, line 90 def gets(sep_string = $/) # # If we have more than one line in the buffer or we have reached the # beginning of the file, send the last line in the buffer to the caller. # (This may be +nil+, if the buffer has been exhausted.) # return @line_buffer.pop if @line_buffer.size > 2 or @current_pos.zero? # # If we made it this far, we need to read more data to try and find the # beginning of a line or the beginning of the file. Move the file pointer # back a step, to give us new bytes to read. # @current_pos -= @read_size @file.seek(@current_pos, IO::SEEK_SET) # # Read more bytes and prepend them to the first (likely partial) line in the # buffer. # @line_buffer[0] = "#{@file.read(@read_size)}#{@line_buffer[0]}" @read_size = MAX_READ_SIZE # Set a size for the next read. # # Divide the first line of the buffer based on +sep_string+ and #flatten! # those new lines into the buffer. # @line_buffer[0] = @line_buffer[0].scan(/.*?#{Regexp.escape(sep_string)}|.+/) @line_buffer.flatten! # We have move data now, so try again to read a line... gets(sep_string) end