Class: Fiddle::Pinned

Inherits:
Object
  • Object
show all
Defined in:
lib/fiddle/ffi_backend.rb,
ext/fiddle/pinned.c

Instance Method Summary collapse

Constructor Details

#Fiddle::Pinned.new(object) ⇒ Object

Create a new pinned object reference. The Fiddle::Pinned instance will prevent the GC from moving object.



52
53
54
# File 'ext/fiddle/pinned.c', line 52

def initialize(object)
  @object = object
end

Instance Method Details

#clearObject

Clear the reference to the object this is pinning.



83
84
85
# File 'ext/fiddle/pinned.c', line 83

def clear
  @object = nil
end

#cleared?Boolean

Returns true if the reference has been cleared, otherwise returns false.

Returns:

  • (Boolean)


97
98
99
# File 'ext/fiddle/pinned.c', line 97

def cleared?
  @object.nil?
end

#refObject

Return the object that this pinned instance references.



66
67
68
69
70
71
# File 'ext/fiddle/pinned.c', line 66

def ref
  if @object.nil?
    raise ClearedReferenceError, "`ref` called on a cleared object"
  end
  @object
end