Class: XRB::Buffer

Inherits:
Object
  • Object
show all
Defined in:
lib/xrb/buffer.rb

Overview

Represents a string buffer with a given path.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, path: "<string>") ⇒ Buffer

Create a new buffer from a string.



12
13
14
15
# File 'lib/xrb/buffer.rb', line 12

def initialize(string, path: "<string>")
	@string = string
	@path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



18
19
20
# File 'lib/xrb/buffer.rb', line 18

def path
  @path
end

#the path name of the buffer.(pathnameofthebuffer.) ⇒ Object (readonly)



18
# File 'lib/xrb/buffer.rb', line 18

attr :path

Class Method Details

.load(string) ⇒ Object

Create a buffer from the specified string.



51
52
53
# File 'lib/xrb/buffer.rb', line 51

def self.load(string)
	Buffer.new(string).freeze
end

.load_file(path) ⇒ Object

Create a buffer from the specified file.



44
45
46
# File 'lib/xrb/buffer.rb', line 44

def self.load_file(path)
	FileBuffer.new(path).freeze
end

Instance Method Details

#encodingObject



32
33
34
# File 'lib/xrb/buffer.rb', line 32

def encoding
	@string.encoding
end

#freezeObject

Freeze the buffer and its contents.



22
23
24
25
26
27
28
29
# File 'lib/xrb/buffer.rb', line 22

def freeze
	return self if frozen?
	
	@string.freeze
	@path.freeze
	
	super
end

#readObject



37
38
39
# File 'lib/xrb/buffer.rb', line 37

def read
	@string
end

#to_bufferObject



56
57
58
# File 'lib/xrb/buffer.rb', line 56

def to_buffer
	self
end