class File
Attributes
io[R]
Public Class Methods
foreach(path, rs = '',&block)
click to toggle source
# File lib/file.rb, line 121 def self.foreach(path, rs = '',&block) self.open(path).each_line(block) end
new(path)
click to toggle source
# File lib/file.rb, line 7 def initialize(path) if @@vfile.include? path vfile = @@vfile[path] @io = vfile.io @hash = @io.string.hash else @io = StringIO.new '' @hash = ''.hash @@vfile[path] = self end @path = path @buf = [] @old_hash = @hash - 1 end
open(path,&block)
click to toggle source
# File lib/file.rb, line 125 def self.open(path,&block) f = self.new(path) block.call f if block f end
Public Instance Methods
<<(str)
click to toggle source
# File lib/file.rb, line 22 def <<(str) self.write(str) end
clear()
click to toggle source
# File lib/file.rb, line 108 def clear @io.close @io = StringIO.new '' self end
close()
click to toggle source
# File lib/file.rb, line 114 def close @buf = nil @hash = nil @old_hash = nil @path = nil end
each_line(rs = "",limit = 0) { |x| ... }
click to toggle source
# File lib/file.rb, line 36 def each_line(rs = "",limit = 0) @io.string.split("\n").each do |x| yield x end end
getc()
click to toggle source
# File lib/file.rb, line 42 def getc unless @old_hash == @hash @old_hash = @hash @buf = self.to_s.split('') end @buf.shift end
gets()
click to toggle source
# File lib/file.rb, line 50 def gets buf = '' ch = '' while (ch = self.getc) != "\n" && ch buf << ch end buf << ch.to_s end
read(length = nil,outbuf = '')
click to toggle source
# File lib/file.rb, line 63 def read(length = nil,outbuf = '') buf = '' if length (0..length).each do buf << self.getc end outbuf.sub!(/^.#{length}/,buf) else outbuf.gsub!(/./,'') outbuf << self.readlines.join('') end buf end
read_nonblock(maxlen, outbuf = '')
click to toggle source
# File lib/file.rb, line 77 def read_nonblock(maxlen, outbuf = '') read(maxlen,outbuf) end
readchar()
click to toggle source
# File lib/file.rb, line 89 def readchar ch = self.getc raise EOFError unless ch end
readline()
click to toggle source
# File lib/file.rb, line 94 def readline line = self.gets raise EOFError unless line line end
readlines(rs = '',limit = 0)
click to toggle source
# File lib/file.rb, line 100 def readlines(rs = '',limit = 0) lines = [] self.each_line(rs,limit) do |l| lines << l end lines end
readpartial(maxlen, outbuf = '')
click to toggle source
# File lib/file.rb, line 81 def readpartial(maxlen, outbuf = '') read(maxlen,outbuf) end
sysread(maxlen, outbuf = '')
click to toggle source
# File lib/file.rb, line 85 def sysread(maxlen, outbuf = '') read(maxlen,outbuf) end
to_s()
click to toggle source
# File lib/file.rb, line 26 def to_s @io.string end
ungetc(ch)
click to toggle source
# File lib/file.rb, line 59 def ungetc(ch) @buf.unshift(ch) end
write(str)
click to toggle source
# File lib/file.rb, line 30 def write(str) c = @io.write(str) @hash = self.to_s.hash c end