Sha256: 1276b07991a43d1cd60e975f752f8ca0475595bd5c6fd85cae2d836e8a960a83

Contents?: true

Size: 850 Bytes

Versions: 3

Compression:

Stored size: 850 Bytes

Contents

# frozen_string_literal: true
module GLib
  # Common methods for container classes: Array, PtrArray, List, SList and
  # HashTable.
  module ContainerClassMethods
    def wrap(typespec, ptr)
      # HACK: wrap and from are almost the same!
      ptr = case ptr
            when nil
              nil
            when FFI::Pointer
              ptr
            when GirFFI::BoxedBase
              ptr.to_ptr
            end

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gir_ffi-0.9.5 lib/ffi-glib/container_class_methods.rb
gir_ffi-0.9.4 lib/ffi-glib/container_class_methods.rb
gir_ffi-0.9.3 lib/ffi-glib/container_class_methods.rb