Class: DRb::WeakIdConv::WeakSet

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/drb/weakidconv.rb

Instance Method Summary collapse

Constructor Details

#initializeWeakSet

Returns a new instance of WeakSet.



14
15
16
17
18
# File 'lib/drb/weakidconv.rb', line 14

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

Instance Method Details

#add(obj) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# 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) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# 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