class YARP::LibRubyParser::YPString

This object represents a yp_string_t. We only use it as an opaque pointer, so it doesn’t have to be an FFI::Struct.

Constants

SIZEOF

Attributes

pointer[R]

Public Class Methods

new(pointer) click to toggle source
# File yarp/ffi.rb, line 140
def initialize(pointer)
  @pointer = pointer
end
with(filepath) { |new(pointer)| ... } click to toggle source

Yields a yp_string_t pointer to the given block.

# File yarp/ffi.rb, line 157
def self.with(filepath, &block)
  pointer = FFI::MemoryPointer.new(SIZEOF)

  begin
    raise unless LibRubyParser.yp_string_mapped_init(pointer, filepath)
    yield new(pointer)
  ensure
    LibRubyParser.yp_string_free(pointer)
    pointer.free
  end
end

Public Instance Methods

length() click to toggle source
# File yarp/ffi.rb, line 148
def length
  LibRubyParser.yp_string_length(pointer)
end
read() click to toggle source
# File yarp/ffi.rb, line 152
def read
  source.read_string(length)
end
source() click to toggle source
# File yarp/ffi.rb, line 144
def source
  LibRubyParser.yp_string_source(pointer)
end