Method: Weak::Set#add?

Defined in:
lib/weak/set.rb

#add?(obj) ⇒ self?

Note:

Weak::Set does not test member equality with == or eql?. Instead, it always checks strict object equality, so that, e.g., different strings are not considered equal, even if they may contain the same string content.

Adds the given object to the weak set and returns self. If the object is already in the set, returns nil.

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)              #=> nil

Parameters:

  • obj (Object)

    an object to add to the weak set

Returns:

  • (self, nil)

    self if the object was added, nil if it was part of the set already



389
390
391
# File 'lib/weak/set.rb', line 389

def add?(obj)
  add(obj) unless include?(obj)
end