Method: Weak::Set#add

Defined in:
lib/weak/set.rb

#add(obj) ⇒ self Also known as: <<

Adds the given object to the weak set and return self. Use #merge to add many elements at once.

In contrast to other "regular" objects, we will not retain a strong reference to the added object. Unless some other live objects still references the object, it will eventually be garbage-collected.

Examples:

Weak::Set[1, 2].add(3)                #=> #<Weak::Set {1, 2, 3}>
Weak::Set[1, 2].add([3, 4])           #=> #<Weak::Set {1, 2, [3, 4]}>
Weak::Set[1, 2].add(2)                #=> #<Weak::Set {1, 2}>

Parameters:

  • obj (Object)

    an object

Returns:

  • (self)
[View source]

# File 'lib/weak/set.rb', line 181