Module: GLib::ContainerClassMethods

Included in:
Array, HashTable, PtrArray
Defined in:
lib/ffi-glib/container_class_methods.rb

Overview

Common methods for container classes: Array, PtrArray, List, SList and HashTable.

Instance Method Summary collapse

Instance Method Details

#from(typespec = :void, obj) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ffi-glib/container_class_methods.rb', line 25

def from(typespec = :void, obj)
  case obj
  when nil
    nil
  when FFI::Pointer
    wrap typespec, obj
  when self
    obj.reset_typespec typespec
  when GirFFI::BoxedBase
    wrap typespec, obj.to_ptr
  else
    from_enumerable typespec, obj
  end
end

#wrap(typespec, ptr) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ffi-glib/container_class_methods.rb', line 7

def wrap(typespec, ptr)
  # HACK: wrap and from are almost the same!
  ptr = case ptr
        when nil
          nil
        when FFI::Pointer
          ptr
        when self
          ptr.to_ptr
        when GirFFI::BoxedBase
          ptr.to_ptr
        end

  super(ptr).tap do |container|
    container.reset_typespec typespec if container
  end
end