Sha256: 4b280dc1e8c809ea5c8ac596b2a94806de0bf0bb37f541a6362bb20cf652ffd4

Contents?: true

Size: 851 Bytes

Versions: 8

Compression:

Stored size: 851 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 self, GirFFI::BoxedBase
              ptr.to_ptr
            end

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

    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
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gir_ffi-0.17.0 lib/ffi-glib/container_class_methods.rb
gir_ffi-0.16.1 lib/ffi-glib/container_class_methods.rb
gir_ffi-0.16.0 lib/ffi-glib/container_class_methods.rb
gir_ffi-0.15.9 lib/ffi-glib/container_class_methods.rb
gir_ffi-0.15.8 lib/ffi-glib/container_class_methods.rb
gir_ffi-0.15.7 lib/ffi-glib/container_class_methods.rb
gir_ffi-0.15.6 lib/ffi-glib/container_class_methods.rb
gir_ffi-0.15.5 lib/ffi-glib/container_class_methods.rb