Class: XRB::IOBuffer
- Inherits:
-
Object
- Object
- XRB::IOBuffer
- Defined in:
- lib/xrb/buffer.rb
Overview
Represents an IO buffer with a given path.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
- #the path name of the buffer.(pathnameofthebuffer.) ⇒ Object readonly
Instance Method Summary collapse
- #encoding ⇒ Object
-
#freeze ⇒ Object
Freeze the buffer, caching the contents of the IO object.
-
#initialize(io, path: io.inspect) ⇒ IOBuffer
constructor
Create a new IO buffer from an IO object.
-
#read ⇒ Object
Read the contents of the IO object into the buffer.
- #to_buffer ⇒ Object
Constructor Details
#initialize(io, path: io.inspect) ⇒ IOBuffer
Create a new IO buffer from an IO object.
104 105 106 107 108 |
# File 'lib/xrb/buffer.rb', line 104 def initialize(io, path: io.inspect) @io = io @path = path @cache = nil end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
120 121 122 |
# File 'lib/xrb/buffer.rb', line 120 def path @path end |
#the path name of the buffer.(pathnameofthebuffer.) ⇒ Object (readonly)
120 |
# File 'lib/xrb/buffer.rb', line 120 attr :path |
Instance Method Details
#encoding ⇒ Object
123 124 125 |
# File 'lib/xrb/buffer.rb', line 123 def encoding read.encoding end |
#freeze ⇒ Object
Freeze the buffer, caching the contents of the IO object.
111 112 113 114 115 116 117 |
# File 'lib/xrb/buffer.rb', line 111 def freeze return self if frozen? read super end |
#read ⇒ Object
Read the contents of the IO object into the buffer.
128 129 130 131 132 133 134 135 |
# File 'lib/xrb/buffer.rb', line 128 def read unless @cache @cache = @io.read.freeze @io.close end return @cache end |
#to_buffer ⇒ Object
138 139 140 |
# File 'lib/xrb/buffer.rb', line 138 def to_buffer Buffer.new(self.read, path: @path) end |