Class: Rucc::FileIOList

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rucc/file_io_list.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ FileIOList

Returns a new instance of FileIOList.

Parameters:



8
9
10
11
# File 'lib/rucc/file_io_list.rb', line 8

def initialize(file)
  @files = [file]
  @stashed = []  # buffer for stashed files
end

Instance Method Details

#currentFileIO

Returns:



15
16
17
# File 'lib/rucc/file_io_list.rb', line 15

def current
  @files.last
end

#readcChar, NilClass

Returns:

  • (Char, NilClass)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rucc/file_io_list.rb', line 20

def readc
  while true
    c = current.readc
    if !c.nil?  # not EOF
      return c
    end

    if @files.size == 1
      return c
    end
    f = @files.pop
    f.close
    next
  end
  raise "Must not reach here!"
end

#stream_depthObject



52
53
54
# File 'lib/rucc/file_io_list.rb', line 52

def stream_depth
  @files.size
end

#stream_stash(files) ⇒ Object

Parameters:



43
44
45
46
# File 'lib/rucc/file_io_list.rb', line 43

def stream_stash(files)
  @stashed.push(@files)
  @files = files
end

#stream_unstashObject



48
49
50
# File 'lib/rucc/file_io_list.rb', line 48

def stream_unstash
  @files = @stashed.pop
end

#unreadc(c) ⇒ Object

Parameters:

  • (Char, NilClass)


38
39
40
# File 'lib/rucc/file_io_list.rb', line 38

def unreadc(c)
  current.unreadc(c)
end