File: reference.rb

package info (click to toggle)
ruby-ref 1.0.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 332 kB
  • ctags: 186
  • sloc: ruby: 1,107; java: 92; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 825 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module Ref
  # This class serves as a generic reference mechanism to other objects. The
  # actual reference can be either a WeakReference, SoftReference, or StrongReference.
  class Reference
    # The object id of the object being referenced.
    attr_reader :referenced_object_id
    
    # Create a new reference to an object.
    def initialize(obj)
      raise NotImplementedError.new("cannot instantiate a generic reference")
    end
    
    # 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.
    def object
      raise NotImplementedError
    end

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