123456789_123456789_123456789_123456789_123456789_

Class: Prism::LibRubyParser::PrismString

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_string_t. We only use it as an opaque pointer, so it doesn’t have to be an FFI::Struct.

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(pointer) ⇒ PrismString

[ GitHub ]

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

def initialize(pointer)
  @pointer = pointer
end

Class Method Details

.with(filepath, &block)

Yields a pm_string_t pointer to the given block.

[ GitHub ]

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

def self.with(filepath, &block)
  pointer = FFI::MemoryPointer.new(SIZEOF)

  begin
    raise unless LibRubyParser.pm_string_mapped_init(pointer, filepath)
    yield new(pointer)
  ensure
    LibRubyParser.pm_string_free(pointer)
    pointer.free
  end
end

Instance Attribute Details

#pointer (readonly)

[ GitHub ]

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

attr_reader :pointer

Instance Method Details

#length

[ GitHub ]

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

def length
  LibRubyParser.pm_string_length(pointer)
end

#read

[ GitHub ]

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

def read
  source.read_string(length)
end

#source

[ GitHub ]

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

def source
  LibRubyParser.pm_string_source(pointer)
end