Method: Immutable::Set#add

Defined in:
lib/immutable/set.rb

#add(item) ⇒ Set Also known as: <<

Return a new Set with item added. If item is already in the set, return self.

Examples:

Immutable::Set[1, 2, 3].add(4) # => Immutable::Set[1, 2, 4, 3]
Immutable::Set[1, 2, 3].add(2) # => Immutable::Set[1, 2, 3]

Parameters:

  • item (Object)

    The object to add

Returns:



105
106
107
# File 'lib/immutable/set.rb', line 105

def add(item)
  include?(item) ? self : self.class.alloc(@trie.put(item, nil))
end