Class: Ref::WeakReference::ReferencePointer

Inherits:
Object
  • Object
show all
Defined in:
lib/ref/weak_reference/pure_ruby.rb

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ ReferencePointer

Returns a new instance of ReferencePointer.



9
10
11
12
# File 'lib/ref/weak_reference/pure_ruby.rb', line 9

def initialize(object)
  @referenced_object_id = object.__id__
  add_backreference(object)
end

Instance Method Details

#cleanupObject



14
15
16
17
# File 'lib/ref/weak_reference/pure_ruby.rb', line 14

def cleanup
  obj = ObjectSpace._id2ref(@referenced_object_id) rescue nil
  remove_backreference(obj) if obj
end

#objectObject



19
20
21
22
23
24
# File 'lib/ref/weak_reference/pure_ruby.rb', line 19

def object
  obj = ObjectSpace._id2ref(@referenced_object_id)
  obj if verify_backreferences(obj)
rescue RangeError
  nil
end