Class: GObjectIntrospection::Strv

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ffi-gobject_introspection/strv.rb

Overview

Represents a null-terminated array of strings. GLib uses this construction, but does not provide any actual functions for this class. In a sense, this is a specialization of GirFFI::ZeroTerminated.

Direct Known Subclasses

GLib::Strv

Constant Summary collapse

POINTER_SIZE =
FFI.type_size(:pointer)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr) ⇒ Strv

Returns a new instance of Strv.



15
16
17
# File 'lib/ffi-gobject_introspection/strv.rb', line 15

def initialize(ptr)
  @ptr = ptr
end

Class Method Details

.wrap(ptr) ⇒ Object



31
32
33
# File 'lib/ffi-gobject_introspection/strv.rb', line 31

def self.wrap(ptr)
  new ptr unless ptr.null?
end

Instance Method Details

#eachObject



23
24
25
26
27
28
29
# File 'lib/ffi-gobject_introspection/strv.rb', line 23

def each
  offset = 0
  while (ptr = fetch_ptr offset)
    offset += POINTER_SIZE
    yield ptr.read_string.force_encoding(Encoding::UTF_8)
  end
end

#to_ptrObject



19
20
21
# File 'lib/ffi-gobject_introspection/strv.rb', line 19

def to_ptr
  @ptr
end