Module: GMSEC::API::Finalizer

Defined in:
lib/gmsec/api.rb

Instance Method Summary collapse

Instance Method Details

#initialize(*args, **kwargs) ⇒ Object

Allows us to specify #destroy! to be called on an instance during GC.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gmsec/api.rb', line 6

def initialize(*args, **kwargs)
  ObjectSpace.define_finalizer(self, self.class.method(:destroy!).to_proc)

  # If there is a `native_value` keyword argument supplied, assign
  # the value to native_object
  if native_object = kwargs.delete(:native_object)
    @native_object = native_object
  else
    if respond_to? :native_object_initializer
      initialize_native_object do |pointer|
        native_object_initializer(pointer)
      end
    end
  end

  if kwargs.empty?
    super(*args)
  else
    super(*args, **kwargs)
  end
end