Class: WeakRef
| Relationships & Source Files | |
| Namespace Children | |
| Exceptions: | |
| Super Chains via Extension / Inclusion / Inheritance | |
| Class Chain: 
          self,
          Delegator
         | |
| Instance Chain: 
          self,
          Delegator
         | |
| Inherits: | Delegator 
 | 
| Defined in: | lib/weakref.rb | 
Overview
Weak Reference class that allows a referenced object to be garbage-collected.
A WeakRef may be used exactly like the object it references.
Usage:
foo = Object.new            # create a new object instance
p foo.to_s                  # original's class
foo = WeakRef.new(foo)      # reassign foo with WeakRef instance
p foo.to_s                  # should be same class
GC.start                    # start the garbage collector
p foo.to_s                  # should raise exception (recycled)Constant Summary
- 
    VERSION =
    
 # File 'lib/weakref.rb', line 20"0.1.3"
Class Method Summary
- 
    
      .new(orig)  ⇒ WeakRef 
    
    constructor
    Creates a weak reference to orig
Instance Attribute Summary
- 
    
      #weakref_alive?  ⇒ Boolean 
    
    readonly
    Returns true if the referenced object is still alive. 
Instance Method Summary
- #__getobj__ Internal use only
- #__setobj__(obj) Internal use only
Constructor Details
    .new(orig)  ⇒ WeakRef 
  
Creates a weak reference to orig
# File 'lib/weakref.rb', line 34
def initialize(orig) case orig when true, false, nil @delegate_sd_obj = orig else @@__map[self] = orig end super end
Instance Attribute Details
    #weakref_alive?  ⇒ Boolean  (readonly)
  
Returns true if the referenced object is still alive.
# File 'lib/weakref.rb', line 55
def weakref_alive? @@__map.key?(self) or defined?(@delegate_sd_obj) end
Instance Method Details
#__getobj__
    This method is for internal use only.
  
  [ GitHub ]
# File 'lib/weakref.rb', line 44
def __getobj__ # :nodoc: @@__map[self] or defined?(@delegate_sd_obj) ? @delegate_sd_obj : Kernel::raise(RefError, "Invalid Reference - probably recycled", Kernel::caller(2)) end
#__setobj__(obj)
    This method is for internal use only.
  
  [ GitHub ]
# File 'lib/weakref.rb', line 49
def __setobj__(obj) # :nodoc: end