Class: Ref::Reference
- Inherits:
-
Object
- Object
- Ref::Reference
- 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
Instance Attribute Summary collapse
-
#referenced_object_id ⇒ Object
readonly
The object id of the object being referenced.
Instance Method Summary collapse
-
#initialize(obj) ⇒ Reference
constructor
Create a new reference to an object.
- #inspect ⇒ Object
-
#object ⇒ Object
Get the referenced object.
Constructor Details
#initialize(obj) ⇒ Reference
Create a new reference to an object.
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_id ⇒ Object (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
#inspect ⇒ Object
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 |
#object ⇒ Object
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.
15 16 17 |
# File 'lib/ref/reference.rb', line 15 def object raise NotImplementedError end |