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 104

def initialize(pointer)
  @pointer = pointer
end

Class Method Details

.with(&block)

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 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 Attribute Details

#pointer (readonly)

[ GitHub ]

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

attr_reader :pointer

Instance Method Details

#length

[ GitHub ]

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

def length
  LibRubyParser.pm_buffer_length(pointer)
end

#read

[ GitHub ]

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

def read
  value.read_string(length)
end

#value

[ GitHub ]

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

def value
  LibRubyParser.pm_buffer_value(pointer)
end