XRBSourceXRBFileBuffer

class FileBuffer

Represents a file buffer with a given path.

Definitions

def initialize(path)

Create a new file buffer from a file path.

Signature

parameter path String

the path to the file.

Implementation

def initialize(path)
	@path = path
	@cache = nil
end

def freeze

Freeze the buffer, caching the contents of the file.

Implementation

def freeze
	return self if frozen?
	
	read
	
	super
end

attr :path

Signature

attribute String

the path name of the buffer.

def encoding

Signature

returns Encoding

the encoding of the buffer.

Implementation

def encoding
	read.encoding
end

def read

Read the contents of the file into the buffer.

Signature

returns String

the content of the buffer.

Implementation

def read
	@cache ||= File.read(@path).freeze
end

def to_buffer

Signature

returns Buffer

a buffer with the contents of the file.

Implementation

def to_buffer
	Buffer.new(self.read, @path)
end