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
- .new ⇒ WeakSet constructor
Instance Method Summary
-
#<<(object)
See additional method definition at line 12.
- #[](object) (also: #include?)
- #[]=(object, _present)
- #each(&block)
-
#include?(object)
Alias for #[].
-
#initialize_copy(other)
See additional method definition at line 16.
- #to_a
Constructor Details
.new ⇒ WeakSet
# 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.
# 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 #[].
# File 'activesupport/lib/active_support/weak_set.rb', line 35
alias_method :include?, :[]
#initialize_copy(other)
See additional method definition at line 16.
# 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