123456789_123456789_123456789_123456789_123456789_

Class: ActiveSupport::WeakSet

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ObjectSpace::WeakMap
Instance Chain:
self, ObjectSpace::WeakMap
Inherits: ObjectSpace::WeakMap
Defined in: activesupport/lib/active_support/weak_set.rb,
activesupport/lib/active_support/weak_set.rb

Overview

On TruffleRuby ObjectSpace::WeakMap keys are strong references. So we use object_id as a key and the actual object as a value.

JRuby for now doesn't have Class#descendant, but when it will, it will likely have the same WeakMap semantic than Truffle so we future proof this as much as possible.

Class Method Summary

Instance Method Summary

Constructor Details

.new ⇒ WeakSet

[ GitHub ]

  
# File 'activesupport/lib/active_support/weak_set.rb', line 28

def initialize
  @map = ObjectSpace::WeakMap.new
end

Instance Method Details

#<<(object)

See additional method definition at line 12.

[ GitHub ]

  
# File 'activesupport/lib/active_support/weak_set.rb', line 49

def <<(object)
  self[object] = true
end

#[](object) Also known as: #include?

[ GitHub ]

  
# File 'activesupport/lib/active_support/weak_set.rb', line 32

def [](object)
  @map.key?(object.object_id)
end

#[]=(object, _present)

[ GitHub ]

  
# File 'activesupport/lib/active_support/weak_set.rb', line 37

def []=(object, _present)
  @map[object.object_id] = object
end

#each(&block)

[ GitHub ]

  
# File 'activesupport/lib/active_support/weak_set.rb', line 45

alias_method :each, :each_key

#include?(object)

Alias for #[].

[ GitHub ]

  
# File 'activesupport/lib/active_support/weak_set.rb', line 35

alias_method :include?, :[]

#initialize_copy(other)

See additional method definition at line 16.

[ GitHub ]

  
# File 'activesupport/lib/active_support/weak_set.rb', line 53

def initialize_copy(other)
  super
  other.each { |object| self << object }
end

#to_a

[ GitHub ]

  
# File 'activesupport/lib/active_support/weak_set.rb', line 41

alias_method :to_a, :keys