123456789_123456789_123456789_123456789_123456789_

Class: Prism::LibRubyParser::PrismBuffer

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/prism/ffi.rb

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

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(pointer) ⇒ PrismBuffer

[ GitHub ]

  
# File 'lib/prism/ffi.rb', line 128

def initialize(pointer)
  @pointer = pointer
end

Class Method Details

.with

Initialize a new buffer and yield it to the block. The buffer will be automatically freed when the block returns.

[ GitHub ]

  
# File 'lib/prism/ffi.rb', line 146

def self.with
  FFI::MemoryPointer.new(SIZEOF) do |pointer|
    raise unless LibRubyParser.pm_buffer_init(pointer)
    return yield new(pointer)
  ensure
    LibRubyParser.pm_buffer_free(pointer)
  end
end

Instance Attribute Details

#pointer (readonly)

[ GitHub ]

  
# File 'lib/prism/ffi.rb', line 126

attr_reader :pointer

Instance Method Details

#length

[ GitHub ]

  
# File 'lib/prism/ffi.rb', line 136

def length
  LibRubyParser.pm_buffer_length(pointer)
end

#read

[ GitHub ]

  
# File 'lib/prism/ffi.rb', line 140

def read
  value.read_string(length)
end

#value

[ GitHub ]

  
# File 'lib/prism/ffi.rb', line 132

def value
  LibRubyParser.pm_buffer_value(pointer)
end