Class: Prism::LibRubyParser::PrismBuffer
Overview
This object represents a pm_buffer_t. We only use it as an opaque pointer, so it doesn’t need to know the fields of pm_buffer_t.
Constant Summary collapse
- SIZEOF =
:nodoc:
LibRubyParser.pm_buffer_sizeof
Instance Attribute Summary collapse
-
#pointer ⇒ Object
readonly
Returns the value of attribute pointer.
Class Method Summary collapse
-
.with(&block) ⇒ Object
Initialize a new buffer and yield it to the block.
Instance Method Summary collapse
-
#initialize(pointer) ⇒ PrismBuffer
constructor
A new instance of PrismBuffer.
- #length ⇒ Object
- #read ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(pointer) ⇒ PrismBuffer
Returns a new instance of PrismBuffer.
104 105 106 |
# File 'lib/prism/ffi.rb', line 104 def initialize(pointer) @pointer = pointer end |
Instance Attribute Details
#pointer ⇒ Object (readonly)
Returns the value of attribute pointer.
102 103 104 |
# File 'lib/prism/ffi.rb', line 102 def pointer @pointer end |
Class Method Details
.with(&block) ⇒ Object
Initialize a new buffer and yield it to the block. The buffer will be automatically freed when the block returns.
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/prism/ffi.rb', line 122 def self.with(&block) pointer = FFI::MemoryPointer.new(SIZEOF) begin raise unless LibRubyParser.pm_buffer_init(pointer) yield new(pointer) ensure LibRubyParser.pm_buffer_free(pointer) pointer.free end end |
Instance Method Details
#length ⇒ Object
112 113 114 |
# File 'lib/prism/ffi.rb', line 112 def length LibRubyParser.pm_buffer_length(pointer) end |
#read ⇒ Object
116 117 118 |
# File 'lib/prism/ffi.rb', line 116 def read value.read_string(length) end |
#value ⇒ Object
108 109 110 |
# File 'lib/prism/ffi.rb', line 108 def value LibRubyParser.pm_buffer_value(pointer) end |