In Files

Parent

Files

RD::Part

RD::Part is a pseudo IO class

Attributes

lineno[RW]
pos[RW]
tell[RW]
tree[R]

Public Class Methods

new(content = "", tree = nil, mode = "r") click to toggle source
# File lib/rd/filter.rb, line 74
def initialize(content = "", tree = nil, mode = "r")
  @content = content
  if mode == "r"
    @content.freeze
  end
  @tree = tree
  @pos = 0
  @lineno = 0
  @unget = nil
end

Public Instance Methods

<<(arg) click to toggle source
# File lib/rd/filter.rb, line 195
def << (arg)
  begin
    @content << arg.to_s
    self
  rescue
    raise IOError
  end
end
each(rs = $/) click to toggle source
Alias for: each_line
each_byte() click to toggle source
# File lib/rd/filter.rb, line 92
def each_byte
  while char = getc
    yield(char)
  end
end
each_line(rs = $/) click to toggle source
# File lib/rd/filter.rb, line 85
def each_line(rs = $/)
  while line = gets
    yield(line)
  end
end
Also aliased as: each
empty?() click to toggle source
# File lib/rd/filter.rb, line 241
def empty?
  @content.empty?
end
eof() click to toggle source
Alias for: eof?
eof?() click to toggle source
# File lib/rd/filter.rb, line 98
def eof?
  @pos == @content.size
end
Also aliased as: eof
getc() click to toggle source
# File lib/rd/filter.rb, line 119
def getc
  get_char(nil)
end
gets(rs = $/) click to toggle source
# File lib/rd/filter.rb, line 152
def gets(rs = $/)
  get_line(nil, rs)
end
printf(format, *args) click to toggle source
# File lib/rd/filter.rb, line 215
def printf(format, *args)
  str = sprintf(format, *args)
  begin
    @content << str
    nil
  rescue
    raise IOError
  end
end
putc(char) click to toggle source
# File lib/rd/filter.rb, line 225
def putc(char)
  self.printf("%c", char)
  char
end
puts(*args) click to toggle source
# File lib/rd/filter.rb, line 230
def puts(*args)
  args.flatten.each do |i|
    self.print(i, "\n")
  end
end
read(length = @content.size - @pos) click to toggle source
# File lib/rd/filter.rb, line 160
def read(length = @content.size - @pos)
  ret = ""
  length.times do 
    ret << getc
  end
  ret
end
readchar() click to toggle source
# File lib/rd/filter.rb, line 123
def readchar
  get_char(true)
end
readline(rs = $/) click to toggle source
# File lib/rd/filter.rb, line 156
def readline(rs = $/)
  get_line(true, $/)
end
readlines(rs = $/) click to toggle source
# File lib/rd/filter.rb, line 168
def readlines(rs = $/)
  ret = []
  each_line(rs) do |line|
    ret.push(line)
  end
  ret
end
rewind() click to toggle source
# File lib/rd/filter.rb, line 176
def rewind
  @pos = 0
end
seek(offset, whence) click to toggle source
# File lib/rd/filter.rb, line 180
def seek(offset, whence)
  case whence
  when 0
    @pos = offset
  when 1
    @pos += offset
  when 2
    @pos += @content.size - 1
  else
    raise Errno::EINVAL
  end
end
to_s() click to toggle source
# File lib/rd/filter.rb, line 245
def to_s
  @content
end
ungetc(char) click to toggle source
# File lib/rd/filter.rb, line 127
def ungetc(char)
  @ungetc = char
  nil
end
write(str) click to toggle source
# File lib/rd/filter.rb, line 236
def write(str)
  @content << str.to_s
  str.to_s.size
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.