Class: Ref::Reference

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

Overview

This class serves as a generic reference mechanism to other objects. The actual reference can be either a WeakReference, SoftReference, or StrongReference.

Direct Known Subclasses

SoftReference, StrongReference, WeakReference

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ Reference

Create a new reference to an object.

Raises:

  • (NotImplementedError)


9
10
11
# File 'lib/ref/reference.rb', line 9

def initialize(obj)
  raise NotImplementedError.new("cannot instantiate a generic reference")
end

Instance Attribute Details

#referenced_object_idObject (readonly)

The object id of the object being referenced.



6
7
8
# File 'lib/ref/reference.rb', line 6

def referenced_object_id
  @referenced_object_id
end

Instance Method Details

#inspectObject



19
20
21
22
# File 'lib/ref/reference.rb', line 19

def inspect
  obj = object
  "<##{self.class.name}: #{obj ? obj.inspect : "##{referenced_object_id} (not accessible)"}>"
end

#objectObject

Get the referenced object. This could be nil if the reference is a WeakReference or a SoftReference and the object has been reclaimed by the garbage collector.

Raises:

  • (NotImplementedError)


15
16
17
# File 'lib/ref/reference.rb', line 15

def object
  raise NotImplementedError
end