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.
102 103 104 105 106 |
# File 'lib/xrb/buffer.rb', line 102 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.
118 119 120 |
# File 'lib/xrb/buffer.rb', line 118 def path @path end |
#the path name of the buffer.(pathnameofthebuffer.) ⇒ Object (readonly)
118 |
# File 'lib/xrb/buffer.rb', line 118 attr :path |
Instance Method Details
#encoding ⇒ Object
121 122 123 |
# File 'lib/xrb/buffer.rb', line 121 def encoding read.encoding end |
#freeze ⇒ Object
Freeze the buffer, caching the contents of the IO object.
109 110 111 112 113 114 115 |
# File 'lib/xrb/buffer.rb', line 109 def freeze return self if frozen? read super end |
#read ⇒ Object
Read the contents of the IO object into the buffer.
126 127 128 129 130 131 132 133 |
# File 'lib/xrb/buffer.rb', line 126 def read unless @cache @cache = @io.read.freeze @io.close end return @cache end |
#to_buffer ⇒ Object
136 137 138 |
# File 'lib/xrb/buffer.rb', line 136 def to_buffer Buffer.new(self.read, path: @path) end |