123456789_123456789_123456789_123456789_123456789_

Class: DRb::WeakIdConv::WeakSet

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, MonitorMixin
Inherits: Object
Defined in: lib/drb/weakidconv.rb

Class Method Summary

Instance Method Summary

Constructor Details

.newWeakSet

[ GitHub ]

  
# File 'lib/drb/weakidconv.rb', line 14

def initialize
  super()
  @immutable = {}
  @map = ObjectSpace::WeakMap.new
end

Instance Method Details

#add(obj)

[ GitHub ]

  
# File 'lib/drb/weakidconv.rb', line 20

def add(obj)
  synchronize do
    begin
      @map[obj] = self
    rescue ArgumentError
      @immutable[obj.__id__] = obj
    end
    return obj.__id__
  end
end

#fetch(ref)

[ GitHub ]

  
# File 'lib/drb/weakidconv.rb', line 31

def fetch(ref)
  synchronize do
    @immutable.fetch(ref) {
      @map.each { |key, _|
        return key if key.__id__ == ref
      }
      raise RangeError.new("invalid reference")
    }
  end
end